I have read doc of Mongo Stitch, but still failed to query mongodb.
The aim is to statistic daily data input in mongodb for recent 15 days. “$create_time” is the datetime string at insertion (eg. “2019-04-20 15:20:30”). The problem is how to group by date.

Any advice is welcome.

{
  "collection": "maoyan",
  "aggregate": [
      {"$project": {
          "create_time":"$create_time",
          "ago_15":{
              "$dateToString": {
                  "format": "%Y-%m-%d",
                  "date": {"$date": "ISODate().getTime() - 1000*3600*24*15)"
              }
          }
      }
  },
  {
    "$match": {
      "create_time": {
        "$gt": "$ago_15"
      }
    }
  },
  {
    "$group": {
      "_id": {
        "$substr": [
          "$create_time",
          0,
          10
        ]
      },
      
        "count":{"$sum":1}
        
    }
  }
]
}
1 Like

Any update on this? How to get this working?

I don’t use Mongo. But from the documentation:

During execution, Redash will convert it into either a db.collection.find() call or a db.collection.aggregate() call.

So if you can write your query in either of those syntaxes you can convert it to a query in Redash.