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
Do you want to request a feature or report a bug?
bug
What is the current behavior?
I am using updateOne with upsert: true to update or create a document. I need to check if a document was created (upserted) or updated. I tried using res.nModified; but it returns 0 if the document was upserted OR not updated.
What is the expected behavior?
I need to know if a document was updated or upserted. If nModified == 0 it could be that the document got upserted or not updated at all as it didn't had any changes.
I could use fineOneAndUpdate however, updatedExisting is always true even if the data did not change for an update.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
mongoose: 5.12.1
mongodb: 3.6.5
node: v14.15.4
The text was updated successfully, but these errors were encountered:
Do you want to request a feature or report a bug?
bug
What is the current behavior?
I am using
updateOne
withupsert: true
to update or create a document. I need to check if a document was created (upserted) or updated. I tried usingres.nModified;
but it returns 0 if the document was upserted OR not updated.If the current behavior is a bug, please provide the steps to reproduce.
Referencing: https://masteringjs.io/tutorials/mongoose/upsert
result will be:
However
result.upserted
does not exist in types:Property 'upserted' does not exist on type '{ ok: number; n: number; nModified: number; }'.
https://github.com/Automattic/mongoose/blob/master/index.d.ts#L857 is using https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/mongodb/index.d.ts#L2772 which has the following definition:
What is the expected behavior?
I need to know if a document was updated or upserted. If
nModified == 0
it could be that the document got upserted or not updated at all as it didn't had any changes.I could use
fineOneAndUpdate
however,updatedExisting
is always true even if the data did not change for an update.What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
mongoose: 5.12.1
mongodb: 3.6.5
node: v14.15.4
The text was updated successfully, but these errors were encountered: