0

So I'm trying to take a date from the user and then insert it into a mongodb query and then the query would return a number on this specific date. What I'm trying to reach is whenever the user enters a date that doesn't have a value in the db I need the returned result to be 0.

Note: I'm using redash to visualize results.

The query used:

  {
    "collection": "orders",
    "aggregate": [
      {
        "$match": {
          "verified": 1,
          "dateCreated": {
            "$gt": {
              "$humanTime": "{{ Date.start }} 00:00"
            },
            "$lt": {
              "$humanTime": "{{ Date.end }} 00:00"
            }
          }
        }
      },
      {
        "$group": {
          "_id": {
            "$dateToString": {
              "format": "%Y-%m",
              "date": "$dateCreated"
            }
          },
          "count": {
            "$sum": 1
          }
        }
      },
      {
        "$sort": [
          {
            "name": "_id",
            "direction": -1
          }
        ]
      }
    ]
  }

0 Answers0