Answer the question
In order to leave comments, you need to log in
MongoDB how to update nested objects?
there is a database structure:
todolists[
{
name: "Books",
id: ObjectID(заданный Mongo),
needs:[
{
task: "Harry Potter1",
isCompleted: false
},
{
task: "Harry Potter2",
isCompleted: true
}
]
},
{
name: "Places",
id: ObjectID(заданный Mongo),
needs:[
{
task: "Boodapesht",
isCompleted: false
},
{
task: "Varshava",
isCompleted: true
}
]
}
db.get().collection('todolists').findOneAndUpdate({_id: ObjectID(activeID)},
{ $push: {
needs: {
task: todo.task,
isCompleted: todo.isCompleted
}
}
}, {new: true}
...
Answer the question
In order to leave comments, you need to log in
db.todolists.findOneAndUpdate(
{"needs.task": "Varshava"},
{$set: {"needs.$.isCompleted": false}}
);
You that, a relational DB from it want to make? Change the entire object.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question