【问题标题】:Mongo "Unrecognized pipeline stage name: '$filter'"Mongo“无法识别的管道阶段名称:'$filter'”
【发布时间】:2017-06-04 12:17:57
【问题描述】:

我正在尝试在最新的 mongo 3.4.1 服务器和 3.4.1 shell 中执行以下查询。

db.dealer.aggregate(
[
{$match:{salesAreaId:{$in:[ObjectId("5858d03ec5109a098c854802")]}}},
{$lookup:{
    from:"outstanding",
    localField:"_id",
    foreignField:"dealer_id",
    as:"outstandings"
    }},
 {$filter:{
     input:"$outstandings",
     as:"outstandings",
     cond:{
         $is:{"$$outstandings.finalized":false}
         }
     }}
]
)

但它说

Error: command failed: {
"ok" : 0,
"errmsg" : "Unrecognized pipeline stage name: '$filter'",
"code" : 40324,
"codeName" : "Location40324"
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:23:13
doassert@src/mongo/shell/assert.js:13:14
assert.commandWorked@src/mongo/shell/assert.js:266:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1215:5
@(shell):1:1

根据documentation $filter 从 v3.2 开始支持。 任何帮助。

【问题讨论】:

  • $filter 应该被包裹在 $project 管道阶段
  • 谢谢。没错

标签: mongodb


【解决方案1】:

替换下面的代码

db.dealer.aggregate(
[
{$match:{salesAreaId:{$in:[ObjectId("5858d03ec5109a098c854802")]}}},
{$lookup:{
    from:"outstanding",
    localField:"_id",
    foreignField:"dealer_id",
    as:"outstandings"
    }},
 {$project:{
     outstandings:{$filter:{
     input:"$outstandings",
     as:"outstandings",
     cond:{
         $is:{"$$outstandings.finalized":false}
         }
     }
     }
     }
 }
])

【讨论】:

  • 当我这样做时,我得到:MongoError: invalid operator '$is'
猜你喜欢
  • 2014-07-10
  • 2021-02-10
  • 2019-09-01
  • 2020-10-07
  • 2016-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多