Mongo"无法识别的管道阶段名称:' $ filter'"

时间:2017-01-19 17:19:42

标签: mongodb

我试图在最新的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开始支持。 任何帮助。

1 个答案:

答案 0 :(得分: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}
         }
     }
     }
     }
 }
])