I have the following code:
connection((db) => {
db.collection(\'orders\')
.updateOne(
{ \"_id\": req.body
Tough @Spraw's answer is right for some cases, but sometimes it doesn't work. I think the convenient answer is updateOne({_id: new ObjectID(req.body._id)}, {$set: {"name": req.body.name}}, callback)
.
the _id
in mongodb
is a BSON
object and should be instantiated.
This might happen if the collection schema is missing the field that is to be updated. If the schema is not strict (i.e, isStrict: false), check the update operator. In some cases, the new update value can be same as existing value. In this case, mongoose returns
{ n: 1, nModified: 0, ok: 1 }