Aggregate query with where condition

前端 未结 2 1604
别跟我提以往
别跟我提以往 2021-02-19 05:40

How could the following SQL query be converted for Mongo:

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


        
相关标签:
2条回答
  • 2021-02-19 05:54

    Something like:

    db.myTable.aggregate([
      { $match: { mydate: { $lte: new Date('12/01/1998') } } },
      { $group: {
        _id: "$keyid",
        totalqty: { $sum: "$qty" }
      }}
    ])
    
    0 讨论(0)
  • 2021-02-19 05:56

    Can use this -

    db.schoolexamregistration.aggregate([
        { $match: {"exam_session_id":"1523850138707"} },{
         $lookup:
           {
             from: "student",
             localField: "nic_ppt",
             foreignField: "nic_ppt",
             as: "student_detail"
           }
        }
      ])
    
    0 讨论(0)
提交回复
热议问题