mongodb 使用 where 条件聚合查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13294556/
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-09 12:55:00  来源:igfitidea点击:

Aggregate query with where condition

mongodbdatetimeaggregation-framework

提问by user1603400

How could the following SQL query be converted for Mongo:

如何为 Mongo 转换以下 SQL 查询:

SELECT KeyID, SUM(Qty)
FROM Table
WHERE Date <= '1998-12-01' 

回答by Kay

Something like:

就像是:

db.myTable.aggregate([
  { $match: { mydate: { $lte: new Date('12/01/1998') } } },
  { $group: {
    _id: "$keyid",
    totalqty: { $sum: "$qty" }
  }}
])

回答by Ravinath

Can use this -

可以用这个——

db.schoolexamregistration.aggregate([
    { $match: {"exam_session_id":"1523850138707"} },{
     $lookup:
       {
         from: "student",
         localField: "nic_ppt",
         foreignField: "nic_ppt",
         as: "student_detail"
       }
    }
  ])