i have in mongodb this structure
{doc:
{ array_doc:[....//many documents]}
}
im using mongoskin in mongodb 2.2 with nodejs 0.8
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';
tnx
Don't replicate your key in the value being pulled. Your $pull
operator should look like this instead:
{$pull: {'doc.array_doc': {code_doc: code_doc}}}