mongodb 字段“$_id”必须是累加器对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44042329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:57:02  来源:igfitidea点击:

The Field "$_id" must be an accumulator object

mongodbmongodb-queryaggregation-framework

提问by ffritz

I am trying to groupsome documents within mongoDB, right after a $matchstage like this:

我正在groupmongoDB 中尝试一些文档,就在这样的$match阶段之后:

db.trips.aggregate([
  { "$match": {
      "Stop Time": {
        "$lt": "31.07.2013 23:59"
      }
    }
  },
    {   "$group": {
          "$_id": { "Start": "$Start", "End": "$End" },
    }
  }]

However I am getting the following error:

但是我收到以下错误:

"The field '$_id' must be an accumulator object"

“字段‘$_id’必须是累加器对象”

Why does this error show up, and why does it only show up when I include the match stage? Without the match stage, it works just fine.

为什么会出现此错误,为什么仅在我包含比赛阶段时才会出现?没有比赛阶段,它工作得很好。

回答by user3317755

$_idis not an accumulator function it should be _id

$_id不是累加器函数,它应该是_id