获取集合之间的差异非空的项目
Get items where the difference between sets is non-empty
鉴于我有一个数组 ["a", "b", "c"]
,我想获取所有 any 元素为 not[=21= 的文档] 出现在一个领域。例如,如果我有以下项目:
{
a: ["a", "b"]
}
因为“c”不存在,所以应该检索但不是:
{
a: ["a", "b", "c"]
}
如何使用 MongoDB 进行此查询?
可以用$all
匹配a
中的所有元素,$not
用于$all
操作的否定条件,
collection.find({
a: {
$not: {
$all: ["a", "b", "c"]
}
}
})
鉴于我有一个数组 ["a", "b", "c"]
,我想获取所有 any 元素为 not[=21= 的文档] 出现在一个领域。例如,如果我有以下项目:
{
a: ["a", "b"]
}
因为“c”不存在,所以应该检索但不是:
{
a: ["a", "b", "c"]
}
如何使用 MongoDB 进行此查询?
可以用$all
匹配a
中的所有元素,$not
用于$all
操作的否定条件,
collection.find({
a: {
$not: {
$all: ["a", "b", "c"]
}
}
})