"collection": "event",
"aggregate": [
"$project": {
"month": {
"$date": "$startDate"
curl 'http://localhost/api/query_results' -H 'Accept: application/json, text/plain, */*' -H 'Cookie: session=.eJwdjjGLg0AQRv_KMXUKXbxGuObYRBRmxDCJzDYhR8yts24TOc4Y8t-zpHp8xft4Dzhdb8Psobyep3nYwGm8QPmAjx8oQVgK0qMndVF4Uuopuqq7k9kF6RttbTOR_R7RutFpXaDu075Ep00Qxsxxl2OkiHzIhevkNSo9FmTJC7v0u4tUyYIqGXFnRMNna_2IKy4SxaChkLigOcaW9wHXOmvtISP1Eatudf32n-zvPflf8NzA3zzc3v2Qw_MFsLVHzw.DG2bqw.U5SBWIiOFT9VhZJjRuLnST96TnY' -H 'Connection: keep-alive' --data-binary '{"data_source_id":1,"query":"{\n \"collection\": \"event\",\n \"aggregate\": [\n {\n \"$project\": {\n \"month\": {\n \"$date\": \"$startDate\"\n }\n }\n }\n ]\n}","max_age":0,"query_id":5}' --compressed
What do the logs say?
worker_1 | [2017-08-10 07:22:38,603: INFO/MainProcess] Task redash.tasks.execute_query[9b0c71ad-d792-40c8-9c85-f749baabdfa8] succeeded in 0.0139267686754s: QueryExecutionError('Invalid query format. The query is not a valid JSON.',)
It does look valid. Do you know if this is an error that comes from Redash or from Mongo? (you can see the stacktrace in the log file)
Are you making the call with curl or from the UI?
@SebC99 What is the value of {{fromDate}} and {{toDate}} parameter?
My query which is using "$match" and "$date" got a correct result.
"collection": "users",
"aggregate": [
"$match": {
"created_at": {
"$gte": {
"$date": "2017-01-01T15:00:00.000Z"
"$lt": {
"$date": "2018-01-01T15:00:00.000Z"
The reason you get the invalid JSON message is due to the use of $startDate value for a $date extension. While the error message could be clearer, your JSON query is indeed "invalid".
I'm not sure what the $startDate supposed to be, but it doesn't look like a standard thing.