Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongo "Unrecognized pipeline stage name: '$filter'"

Tags:

mongodb

I'm trying to execute following query in latest mongo 3.4.1 server and the 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}
         }
     }}
]
)

But it says

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

According to the documentation $filter is supporting from v3.2 onward. Any help.

like image 422
user2486322 Avatar asked Jan 19 '17 17:01

user2486322


1 Answers

Replace the below code

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}
         }
     }
     }
     }
 }
])
like image 152
ilankumaran k ilankumaran k Avatar answered Oct 25 '22 01:10

ilankumaran k ilankumaran k