Reputation: 11392
Is there a difference, when updating a value in mongodb/mongoose between using $set
:
await Users.findOneAndUpdate({_id:"xxx"},{$set: {name:"Denis"} })
and just setting it like this:
await Users.findOneAndUpdate({_id:"xxx"},{name:"Denis"})
Thanks.
Upvotes: 5
Views: 1002
Reputation: 11975
In the doc, it mentioned that:
By default, if you don't include any update operators in doc, Mongoose will wrap doc in
$set
for you. This prevents you from accidentally overwriting the document.
So there is no difference unless you specify overwrite: true
in options.
Upvotes: 10