Answer the question
In order to leave comments, you need to log in
How in MongoDB to update objects in an array with new keys only?
Given a collection of approximately the following documents:
{
"book": "Dune",
"persons": [
{"name": "Leto", "age": 52},
{"name": "Paul", "age": 15}
]
}
{
"book": "Dune",
"persons": [
{"name": "Leto", "age": 52, "alive": false},
{"name": "Paul", "age": 15, "alive": true}
]
}
Answer the question
In order to leave comments, you need to log in
for one entry
db.books.update( { "persons.name": "Leto" }, { $set: { "persons.$.alive": true }} );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question