db.tasks.find({user:”saturngod”});
is return
{ "_id" : ObjectId("4de20ef97065cc77c80541fd"),
"todo" : [
{
"id" : 1,
"desc" : "hi",
"done" : 0
},
{
"id" : 2,
"desc" : "hello",
"done" : 0
}
], "user" : "saturngod" }
I want to update done = 1 when todo.id=1
So, I wrote
>db.tasks.update({'todo.id':1},{"$set":{todo:{done:1}}});
I lost all todo and only set done : 1
db.tasks.find();
{ "_id" : ObjectId("4de20ef97065cc77c80541fd"), "todo" : { "done" : 1 }, "user" : "saturngod" }
How to update the value ? I want to do like this
{ "_id" : ObjectId("4de20ef97065cc77c80541fd"),
"todo" : [
{
"id" : 1,
"desc" : "hi",
"done" : 1
},
{
"id" : 2,
"desc" : "hello",
"done" : 0
}
], "user" : "saturngod" }
got it.