You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
…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.
If I am not mistaken,
findOneAndUpdate()
with{upsert: 1}
will perform an upsert, butupdateOne()
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 forupdateOne()
(and any other places that{upsert: true}
can work).But an alternative solution could be to throw an error if
{upsert: 1}
is used forupdateOne()
, rather than just silently do the unexpected thing.(Using mongoose 4.11.7 and node v8.1.2 today)
The text was updated successfully, but these errors were encountered: