以下是一些文档示例:
/* 1 */
{
"_id" : ObjectId("566e80fcddf99fd898a11ad8"),
"username" : "dummy_0",
"score" : 10
}
/* 2 */
{
"_id" : ObjectId("566e80fcddf99fd898a11ad9"),
"username" : "dummy_1",
"score" : 20
}
/* 3 */
{
"_id" : ObjectId("566e80fcddf99fd898a11ada"),
"username" : "dummy_1",
"score" : 30
}
我想获取不存在夫妇(用户名/分数)的所有文档。
例如,如果我选择username: dummy_1
并且score: 20
应该检索对象1和3。
首先,我尝试了:
db.foobar.find({ score: { $ne: 20}, username: { $ne: 'dummy_1'}})
但这显然行不通。
你知道我怎么能做到吗?
您可以使用逻辑$or
运算符查询如下。
db.foobar.find( {
$or: [
{ "username": { $ne: "dummy_1" } },
{ "score": { $ne: 20 } }
]
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句