Question : mongodb find and update one field
Answered by : ugly-unicorn-sx86jz0cfjbw
> db.test.findAndModify({
... query: {"id": "test_object"},
... update: {"$set": {"some_key.param2": "val2_new", "some_key.param3": "val3_new"}},
... new: true
... })
{ "_id" : ObjectId("56476e04e5f19d86ece5b81d"), "id" : "test_object", "some_key" : { "param1" : "val1", "param2" : "val2_new", "param3" : "val3_new" }
}
Source : https://stackoverflow.com/questions/10290621/how-do-i-partially-update-an-object-in-mongodb-so-the-new-object-will-overlay | Last Update : Mon, 14 Mar 22
Question : find one and update explain mongo
Answered by : tomer-zaks
//You cannot apply cursor methods to the result of findOne()
//because a single document is returned. You have access to the document directly
Source : https://www.mongodb.com/docs/manual/reference/method/db.collection.findOne/#the-findone-result-document | Last Update : Wed, 04 May 22