mongodb从数组中删除元素

时间:2018-02-09 13:13:34

标签: mongodb

假设我有对象:

{
    "id":"5a759fb9b953782e38366032",
    "question":"change 111",
    "answer":[
        {"_id":"5a759fb9b953782e38366034","a":"new 123"},
        {"_id":"5a75fccdc678791900c87be9","a":"www"},
        {"_id":"5a75fccdc678791900c87be9","a":"ssss"}
        ]
}

我想基于_id从数组中删除元素。我确实试过了

let bulk = Quiz.collection.initializeOrderedBulkOp();
bulk.find({ _id: new ObjectID('5a759fb9b953782e38366034') }).remove();
bulk.find({ _id: new ObjectID('5a75fccdc678791900c87be9') }).remove();
bulk.execute();

没有结果。

我试试

let bulk = Quiz.collection.initializeOrderedBulkOp();
bulk.find({ _id: new ObjectID('5a759fb9b953782e38366032') }).update({$pull:{answer:{_id:'5a759fb9b953782e38366034'}}})
bulk.execute();

没有结果

0 个答案:

没有答案