I’m trying to figure out of we can still replace document using update command on mongo shell 5.0, documentation says we can and even following the exact example provided in it doesn’t work and gives following error:
MongoInvalidArgumentError: Update document requires atomic operators
Test Data:
db.books.insertMany([
{
"_id" : 1,
"item" : "TBD",
"stock" : 0,
"info" : { "publisher" : "1111", "pages" : 430 },
"tags" : [ "technology", "computer" ],
"ratings" : [ { "by" : "ijk", "rating" : 4 }, { "by" : "lmn", "rating" : 5 } ],
"reorder" : false
},
{
"_id" : 2,
"item" : "XYZ123",
"stock" : 15,
"info" : { "publisher" : "5555", "pages" : 150 },
"tags" : [ ],
"ratings" : [ { "by" : "xyz", "rating" : 5 } ],
"reorder" : false
}
]);
Update command to replace:
db.books.update({ item: 'ZZZ135' },{ item: 'ZZZ135',stock: 5,tags: [ 'database' ]},{ upsert: true } )