运算符也不能在过滤条件中使用

时间:2018-06-28 16:53:03

标签: mongodb mongodb-query

我有一个对象数组,其中包含文档中的日期字段,我想使用过滤器匹配数组中的对象元素,我有一个类似于下面的查询

from collections import OrderedDict 
order_dic = list(OrderedDict(sorted(dic.items(), key=lambda x: x[1]['speed'], reverse=True)))

如果我实际上要使用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") ] } ] } } } } } ]) 而不是$or,则在$cond运算符中使用$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 中使用的运算符是否有任何限制?

0 个答案:

没有答案