更新时间:2023-12-05 19:25:16
$pullAll
运算符实际上是特殊情况"快捷方式,适用于仅包含值的数组,例如您的替代情况.
The $pullAll
operator is actually a "special case" shortcut which works on arrays with just values in them, such as your alternate case.
您真正想要的是 $pull
,它的参数是对数组中包含的文档的查询".因此,您的列表将成为 $in
的参数:
What you really want is $pull
and it's argument is a "query" for the documents contained in the array. So your list then becomes an argument to $in
:
db.bios.update(
{ "name.first": "James" },
{
"$pull": {
"awards": { "by": { "$in": ["Stockholm", "Hollywood"] } }
}
}
)
因此在您的另一个示例中,$pullAll
的较长形式为:
So in your other example, a longer form of $pullAll
would be:
db.bios.update(
{ "name.first": "James" },
{
"$pull": { "contribs": { "$in": ["Java","UNIX"] } }
}
)
一样,只是纵向"形式.
Same thing but just the "longhand" form.