Mongo error: "unknown top level operator: $completed_on" for aggregate

I am trying to perform aggregate operation with Mongo which is like follows:

db.inbound_documents.aggregate([{"$match": 
{"$completed_on": 
{"$gte":'2018-05-19 00:00:00',
"$lte":'2017-05-19 00:00:00'}}},
{"$group":
{"_id":"$completed_by","total":{"$sum":1}}}])

completed_on is available in the schema, Still I am not getting that why it is causing that error.

1 answer

  • answered 2018-11-08 10:04 matthPen

    just remove your $ sign before completed_on :

    db.inbound_documents.aggregate([
    {"$match": 
      {"completed_on": 
        {"$gte":'2018-05-19 00:00:00',
        "$lte":'2017-05-19 00:00:00'}}},
      {"$group":
        {"_id":"$completed_by","total":{"$sum":1}}}])