Mongodb Findoneandupdate Function Is Inserting New Document
I just need to update serviceActiveFlag status whenever i make an update api call.After an update api call,i can see a new document with empty vehicle array is created as shown be
Solution 1:
dbModel.findOneAndUpdate()
of mongoose insert a new document only when your filter query(where claus) failed to find the existing document i.e there is no matching document exist in your collection.
So mongoose will insert the new document to the collection. This works similar to upsert:true
of update()
Post a Comment for "Mongodb Findoneandupdate Function Is Inserting New Document"