Aggregate query with where condition

aggregation-framework, datetime, mongodb

Solution

Something like:

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

Problem

How could the following SQL query be converted for Mongo: ``` SELECT KeyID, SUM(Qty) FROM Table WHERE Date <= '1998-12-01' ```

Original source