-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MongoError: FieldPath cannot be constructed with empty string #10182
Comments
@tar-aldev Please, provide script with steps to reproduce. It's too difficult to help without schema, model, query ( You can omit some fields that don't affect the logic / algorithm. |
Without code samples or stack trace, it's unlikely we'll be able to repro this issue. |
I have this JSON valid object (pretty print):
In browser console I can obtain value (=24) |
@supipd MongoDB doesn't allow storing empty string as a key name. Nothing Mongoose can do about this unfortunately. |
Not sure if anyone is gonna get to this issue through Google, as I did, but I had this problem happening to me because I forgot a |
I could also add some other case for people that would land here searching google for the same error. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
I am not sure if it is mongoose specific or mongodb specific.
I am getting this error
Which is, to be honest quite useless. It gives me no infromation about where and how it happened.
I checked my document and it does not have any empty strings at all.
If the current behavior is a bug, please provide the steps to reproduce.
Could it be because of
.populate
? (So it wants Ref not object) But why it saysstring
then? I gues _id is a special datatype and not string.My document with populate looks like this (some fields omitted)
As supposed, the problem is with populated fields.
.save()
will preserve previously populated fields, therefore in my example I tried to populate fields that have been already populated before.However, could it be possible to somehow improve the error message for this?
the mentioned error will be thrown.
What is the expected behavior?
I should be able to call
.save
or if there IS an error, it would be really useful to have a more specific message (ideally to have a field name) as now it is nearly impossible to identify what the problem is.What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node 14
"mongodb": "^3.6.5",
"mongoose": "<=5.10.18",
The text was updated successfully, but these errors were encountered: