聚合查询与where条件

时间:2012-11-08 17:36:06

标签: mongodb datetime aggregation-framework

任何人都可以帮我解决下面写的查询如何转换成mongodb:

Select KeyID, SUM(Qty) from Table where Date <= '1998-12-01' 

(日期格式为YY-MM-DD)

2 个答案:

答案 0 :(得分:44)

你想要像

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

此致

答案 1 :(得分:0)

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

} ])