Mongodb 在Mongo中嵌套$pull命令
我试图从多个数组中删除一个值,而不必发出多个Mongo命令。我必须有我的语法错误,任何帮助将不胜感激 当我尝试时:Mongodb 在Mongo中嵌套$pull命令,mongodb,bson,mongo-c-driver,Mongodb,Bson,Mongo C Driver,我试图从多个数组中删除一个值,而不必发出多个Mongo命令。我必须有我的语法错误,任何帮助将不胜感激 当我尝试时: update = BCON_NEW("$pull", "{", "files.$.like", BCON_UTF8 (account_id), "}", "{", "files.$.hate", BCON_UTF8 (account_id), "}",
update = BCON_NEW("$pull",
"{",
"files.$.like", BCON_UTF8 (account_id),
"}",
"{",
"files.$.hate", BCON_UTF8 (account_id),
"}",
"{",
"files.$.love", BCON_UTF8 (account_id),
"}",
"{",
"files.$.funny", BCON_UTF8 (account_id),
"}",
"{",
"files.$.sad", BCON_UTF8 (account_id),
"}",
"{",
"files.$.anger", BCON_UTF8 (account_id),
"}",
"{",
"files.$.kiss", BCON_UTF8 (account_id),
"}"
);
如果我将其简化为以下内容,它将失败:
update = BCON_NEW("$pull",
"{",
"files.$.like", BCON_UTF8 (account_id),
"}"
);
$pull对它后面的文档进行操作。看见我以前从未见过BCON符号,所以我可能是错的,但如果我理解正确,我相信您的代码创建的文档将如下所示:
{
$pull: { "files.$.like": BCON_UTF8 (account_id) } //Here's the end of your $pull document,
{ "files.$.hate": BCON_UTF8 (account_id) },
{ "files.$.love": BCON_UTF8 (account_id) },
...
},
相反,我想你想要的是这样的东西我没有测试过:
update = BCON_NEW("$pull",
"{",
"files.$.like", BCON_UTF8 (account_id),
"files.$.hate", BCON_UTF8 (account_id),
"files.$.love", BCON_UTF8 (account_id),
"files.$.funny", BCON_UTF8 (account_id),
"files.$.sad", BCON_UTF8 (account_id),
"files.$.anger", BCON_UTF8 (account_id),
"files.$.kiss", BCON_UTF8 (account_id),
"}"
);