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

{upsert: 1} works with some calls but not with others #5839

Closed
joeysino opened this issue Nov 21, 2017 · 0 comments
Closed

{upsert: 1} works with some calls but not with others #5839

joeysino opened this issue Nov 21, 2017 · 0 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@joeysino
Copy link

If I am not mistaken, findOneAndUpdate() with {upsert: 1} will perform an upsert, but updateOne() with {upsert: 1} will not!

If I use {upsert: true} then both work as expected.

This inconsistent behaviour is somewhat confusing for developers.

I guess the most developer-friendly solution is to make {upsert: 1} work for updateOne() (and any other places that {upsert: true} can work).

But an alternative solution could be to throw an error if {upsert: 1} is used for updateOne(), rather than just silently do the unexpected thing.

(Using mongoose 4.11.7 and node v8.1.2 today)

@vkarpov15 vkarpov15 added this to the 4.13.6 milestone Nov 26, 2017
@vkarpov15 vkarpov15 added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Nov 26, 2017
vkarpov15 added a commit that referenced this issue Nov 28, 2017
daprahamian pushed a commit to mongodb/node-mongodb-native that referenced this issue Dec 4, 2017
…e() (#1580)

Re: Automattic/mongoose#5839

This is a very rough edge in the API where findAndModify() treats upsert: 1 as upsert: true, but findOneAndUpdate() and updateX() treat upsert: 1 as upsert: false. CRUD spec does say upsert is a boolean but we've had upsert: 1 in shell examples for a while so it may be worthwhile to support both, especially since truthiness is so common in JS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

2 participants