When I try to add a field to an object, instead of adding the field to the object it deletes all of the previous fields and adds the new field.
data.collection.updateOne({},{$set: {"object": {"hi":0}}},true)
What I want:
object: {
hello: 0,
hi: 0,
}
What I get:
object: {
hi: 0,
}
I tried everything I could but I did not get it to work as I wanted it to.
Here it is:
db.we.updateOne( { },{$set:{"object.hi":0 } } , true)
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.