简体   繁体   English

拉数组mongodb中的子文档

[英]pull subdocument in array mongodb

i have in mongodb this structure 我在mongodb中有这种结构

{doc:
    { array_doc:[....//many documents]}
}

im using mongoskin in mongodb 2.2 with nodejs 0.8 我在nodejs 0.8的mongodb 2.2中使用mongoskin

var code_doc='HSKD41814541211';
var db = mongo.db(perm+"@127.0.0.1:27017/database",{safe:true});
    db.collection('comercio').findAndModify(
    {
        'code':code,
        'email':email,
    },[],{$pull:{'doc.array_doc':{'doc.array_doc.code_doc':code_doc}}},{new:true},function(err,result)

i want to erase a document from array_doc array that have many documents inside, each document inside the array have a unique code_doc... i want to erase the document that match with the variable code_doc='HSKD41814541211'; 我想从array_doc数组中删除一个文档,里面有很多文档,数组中的每个文档都有一个唯一的code_doc ...我想删除与变量code_doc ='HSKD41814541211'匹配的文档。

tnx n

Don't replicate your key in the value being pulled. 不要在要提取的值中复制密钥。 Your $pull operator should look like this instead: 您的$pull运算符应该看起来像这样:

{$pull: {'doc.array_doc': {code_doc: code_doc}}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM