1
db.tasks.find({user:「saturngod」});MongoDB查詢更新
是返回
{ "_id" : ObjectId("4de20ef97065cc77c80541fd"),
"todo" : [
{
"id" : 1,
"desc" : "hi",
"done" : 0
},
{
"id" : 2,
"desc" : "hello",
"done" : 0
}
], "user" : "saturngod" }
我想更新DONE = 1時todo.id = 1
所以,我寫
>db.tasks.update({'todo.id':1},{"$set":{todo:{done:1}}});
我失去了所有的待辦事項和只設置完成:1
db.tasks.find();
{ "_id" : ObjectId("4de20ef97065cc77c80541fd"), "todo" : { "done" : 1 }, "user" : "saturngod" }
如何更新的價值?我想這樣做
{ "_id" : ObjectId("4de20ef97065cc77c80541fd"),
"todo" : [
{
"id" : 1,
"desc" : "hi",
"done" : 1
},
{
"id" : 2,
"desc" : "hello",
"done" : 0
}
], "user" : "saturngod" }