Skip to content
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

undefined not valid in update query #1051

Closed
hartbit opened this issue Aug 14, 2012 · 2 comments
Closed

undefined not valid in update query #1051

hartbit opened this issue Aug 14, 2012 · 2 comments

Comments

@hartbit
Copy link

hartbit commented Aug 14, 2012

I could be wrong but undefined is valid to trigger a $unset in this scenario:

doc.path = undefined;
doc.save();

but not inside a query:

Model.findOneAndUpdate({}, { path: undefined }, callback);

It throws this exception:

CastError: Cast to string failed for value "undefined"

For me, that's a bug. I expected it to work.

@aheckmann
Copy link
Collaborator

Just updated the docs with findAndModfiy details this morning: http://mongoosejs.com/docs/api.html#model_Model-findOneAndUpdate

This behaves the same as with model.update, nothing but casting of the values is applied. if you need $unset,

Model.findOneAndUpdate({}, { $unset: { path: 1 }}, callback);

@bitmage
Copy link

bitmage commented Mar 31, 2014

Aaron - are you saying this behavior is resulting from code in the native driver? I agree with @hartdev, removing undefined values should be handled at the ODM or driver level. If you feel it's the responsibility of the native driver I can pursue it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants