我正在尝试获取数组excluded
中没有_id
的所有文档。
db.sites.find({ "$expr": { '_id': { "$not": { "$in": "$excluded"} } } });
我不使用$nin
,因为$expr
不允许使用。
我会收到以下错误消息:
Error: error: {
"ok" : 0,
"errmsg" : "Expression $in takes exactly 2 arguments. 1 were passed in.",
"code" : 16020,
"codeName" : "Location16020"
}
我可以使用$where
吗?
操作员中的$需要两个参数:
db.sites.find({ $expr: { $not: { $in: [ "$_id", "$excluded" ] } } })
在这里工作示例