选择按字段分组的文档

时间:2015-11-23 11:01:12

标签: mongodb mongodb-query

我有这个电影文件显示时间和日期:

`{
   "_id": ObjectId("5628668c3e82c49245b7acdc"),
   "ticketID": ObjectId("5606d36b5fbd7d76028b4b08"),
   "uid": "50000",
   "day": "Friday",
   "date": "2015-10-23 21:05:00",
   "adult": NumberLong(550),
   "student": NumberLong(550),
   "children": NumberLong(250),
   "limit": NumberLong(20),
   "sold": NumberLong(0) 
},{
   "_id": ObjectId("562866013e82c49045b7acdc"),
   "ticketID": ObjectId("5606d36b5fbd7d76028b4b08"),
   "uid": "50000",
   "day": "Friday",
   "date": "2015-10-23 19:30:00",
   "adult": NumberLong(1050),
   "student": NumberLong(800),
   "children": NumberLong(550),
   "limit": NumberLong(20),
   "sold": NumberLong(0) 
},{
   "_id": ObjectId("562865013e82c49845b7acda"),
   "ticketID": ObjectId("5606d36b5fbd7d76028b4b08"),
   "uid": "50000",
   "day": "Friday",
   "date": "2015-10-23 18:45:00",
   "adult": NumberLong(1500),
   "student": NumberLong(750),
   "children": NumberLong(750),
   "limit": NumberLong(20),
   "sold": NumberLong(0) 
}
`

我想将最终结果分组为“day”,其中“ticketID”匹配,“date”作为对象,并将“adult”,“student”,“children”,“limit”添加到数组

- 更新 -

我希望返回的结构如下:

{
  "_id": "ticketID",
  "day": "Friday",
  "items": [
    {
      "date": date,
      "time": time"adult": price,
      "children": price,
      "student": price,
      "limit": value
    },
    {
      "date": date,
      "time": time"adult": price,
      "children": price,
      "student": price,
      "limit": value
    },
    {
      "date": date,
      "time": time"adult": price,
      "children": price,
      "student": price,
      "limit": value
    }
  ]
}

0 个答案:

没有答案