MongoDB:未知运算符:$ filter

时间:2018-11-11 22:19:16

标签: mongodb mongodb-query aggregation-framework

我试图在我的藏书中找到具有特定批次ID的所有故事的总和。

当我运行以下管道时,

db.getCollection("book").aggregate(
{
  '$match' : {
    active: true,
    stories:{
      $filter: { 
        input: "$stories",
           as: "story",
         cond: { $eq: [ "$$story.batch", "JUL-2018" ] }
         }
    }

  }
},
{
  '$project' : {
    count:{$size: '$stories'}
  }
}
,
{
  '$group' : {
    _id: "1",
    story_count: {$sum: '$count'}
  }
}

)

我得到:

Unable to execute the selected commands

Mongo Server error (MongoCommandException): Command failed with error 2: 'unknown operator: $filter' on server 127.0.0.1:27017. 

The full response is:
{ 
    "ok" : 0.0, 
    "errmsg" : "unknown operator: $filter", 
    "code" : NumberInt(2), 
    "codeName" : "BadValue"
}

我在做什么错了?

0 个答案:

没有答案