Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于更新的MongoDB查询_Mongodb - Fatal编程技术网

用于更新的MongoDB查询

用于更新的MongoDB查询,mongodb,Mongodb,find({user:“saturngod”}) 回归 { "_id" : ObjectId("4de20ef97065cc77c80541fd"), "todo" : [ { "id" : 1, "desc" : "hi", "done" : 0 }, { "id" : 2, "desc" : "hello", "done" : 0 } ], "user" : "s

find({user:“saturngod”})

回归

{ "_id" : ObjectId("4de20ef97065cc77c80541fd"),
 "todo" : [
    {
        "id" : 1,
        "desc" : "hi",
        "done" : 0
    },
    {
        "id" : 2,
        "desc" : "hello",
        "done" : 0
    }
], "user" : "saturngod" }
我想在todo.id=1时更新done=1

所以,我写了

>db.tasks.update({'todo.id':1},{"$set":{todo:{done:1}}});
我丢了所有要做的事情,只做了一件事:1

db.tasks.find()

如何更新值?我想这样做

{ "_id" : ObjectId("4de20ef97065cc77c80541fd"),
 "todo" : [
    {
        "id" : 1,
        "desc" : "hi",
        "done" : 1
    },
    {
        "id" : 2,
        "desc" : "hello",
        "done" : 0
    }
], "user" : "saturngod" }
明白了

db.tasks.update({'todo.id':1},{"$set":{"todo.$.done":1}});
明白了

db.tasks.update({'todo.id':1},{"$set":{"todo.$.done":1}});