Mongodb nor操作员不能';不能在过滤条件下使用
我的文档中有一个包含日期字段的对象数组,我想使用过滤器匹配数组中的对象元素,我有一个类似于下面的查询Mongodb nor操作员不能';不能在过滤条件下使用,mongodb,mongodb-query,Mongodb,Mongodb Query,我的文档中有一个包含日期字段的对象数组,我想使用过滤器匹配数组中的对象元素,我有一个类似于下面的查询 db.getCollection('test').aggregate([ { $match: { key: "test_key" } }, { $project: { testArray: { $filter: { input: '$testArray', as: 'item',
db.getCollection('test').aggregate([
{
$match: {
key: "test_key"
}
},
{
$project: {
testArray: {
$filter: {
input: '$testArray',
as: 'item',
cond: {
$or: [
{
$lt: [
"$$item.date1",
ISODate("2018-05-06 00:00:00.000Z")
]
},
{
$lt: [
"$$item.date2",
ISODate("2018-06-08 00:00:00.000Z")
]
}
]
}
}
}
}
}
])
如果我在$cond
操作符中使用$or
操作符,效果会很好,尽管我实际上想使用$nor
而不是$or
,但是查询报告了以下错误$nor
Failed to execute script.
Error:
Assert: command failed: {
"ok" : 0,
"errmsg" : "Unrecognized expression '$nor'",
"code" : 168,
"codeName" : "InvalidPipelineOperator"
} : aggregate failed
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:16:14
assert.commandWorked@src/mongo/shell/assert.js:370:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1319:5
DBCollection.prototype.aggregate@:1:355
@(shell):1:1
Error: command failed: {
"ok" : 0,
"errmsg" : "Unrecognized expression '$nor'",
"code" : 168,
"codeName" : "InvalidPipelineOperator"
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:16:14
assert.commandWorked@src/mongo/shell/assert.js:370:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1319:5
DBCollection.prototype.aggregate@:1:355
@(shell):1:1
$cond
中使用的运算符是否有任何限制 这不是限制,只是没有像$或这样的运算符。有效的运算符是$和
,$或
,和$不
:不要混淆查询运算符和表达式运算符。@Alexlex感谢您的解释,我确实混淆了查询运算符和表达式运算符。我想我应该用或不在这里来完成我的任务