In my collection, there is only one document.
> db.c20160712.find()
{ \"_id\" : ObjectId(\"57ab909791c3b3a393e9e277\"), \"Dimension_id\" : 2, \"Attribute\
I believe this was changed as a side-effect of introducing the updateOne()
method in addition to update()
and updateMany()
as somewhat of a safeguard to prevent user's from accidentally overriding an entire document.
You can use the replaceOne() method instead, or an update()
without specifying multi:true
.
You did the same mistake as I did. Upon going through the docs I realized the syntax is wrong. Try:
db.c20160712.updateOne(
{ "Attribute" : "good"},
{"Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action"},
{ upsert: true}
)
You should use this code because I was also facing the same problem and then I used this code:
updateOne(
{ _id: new ObjectID(req.params.id) },
{ $set: { title: req.body.bookName, author: req.body.authorName } },
{ upsert: true }
)
and you should also define ObjectID
otherwise the problem will occur again.
const ObjectID = require('mongodb').ObjectID;
Wrong syntax for the second parameter. Please check the docs. It should be:
db.c20160712.updateOne(
{ "Attribute" : "good" },
{ $set: {"Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action" } },
{ upsert: true }
);