Redash: Date format in parameters doesn't work (MongoDB Query)

Created on 2 Mar 2018  路  9Comments  路  Source: getredash/redash

Issue Summary

When using date parameters in MongoDB query, we can't use the date format, but only the number one (timestamp)

Steps to Reproduce

{
  "$match": {
     "_created_at": {
       "$gte": {
         "$date": "{{fromDate}}"
       },
       "$lt": {
         "$date": "{{toDate}}"
        }
       }
    }
}
Bug

Most helpful comment

What works for me is using $ISODate:

"_created_at": {
   "$gte": "ISODate(\"{{ start }}\")"
}

All 9 comments

me too, I store data with unix timestamp,there is no result when i query with date paramters, but i can get data when using number

Any updates on this issue ?
"urt" : { "$gte" : {"$date" : "{{ Start Date }}"}, "$lte" : {"$date" : "{{ End Date }}"} }

That's the only thing stopping us from moving to Redash

Did you try wrapping the value with $humanTime helper?

i.e.:

"urt": {
        "$gte": {
            "$date": {
                "$humanTime": "{{ Start Date }}"
            }
        },
        "$lte": {
            "$date": {
                "$humanTime": "{{ End Date }}"
            }
        }
    }

I have a similar use case and I've tried to wrap it with "$humanTime" helper as well and it's not working

"deliveryDate": {
   "$gt": {
      "$date": {
         "$humanTime": "{{ start }}"
      }   
   },
   "$lte": {
      "$date": {
         "$humanTime": "{{ end }}"
      }   
   }
}

What works for me is using $ISODate:

"_created_at": {
   "$gte": "ISODate(\"{{ start }}\")"
}

Not working like this :

"deliveryDate": {
   "$gt": "ISODate(\"{{ start }}\")",
   "$lte": "ISODate(\"{{ end }}\")"
}

I'm using inputs Date & time

Any update on this? I'm unable to get any of the examples above working.

I found the date/datetime format in redash is incompatible with MongoDB.

铻㈠箷蹇収_2019-03-26_涓嬪崍7_33_56

Hi, is there any update on this?

I would like as well to count events during the last hour, and made the following query:

{
    "collection": "live-providers",
    "aggregate": [{
        "$match": {
            "date": { 
                "$gt": "new ISODate(ISODate().getTime() - 1000 * 60 * 60)"
            }
        }
    } ,{
        "$group": {
            "_id": "$provider",
            "count1": {
                "$sum": "$insert"
            },
            "count2": {
                "$sum": "$delete"
            },
            "coun3t": {
                "$sum": "$updates"
            }
        }
    }, {
        "$sort": [{
            "name": "count1",
            "direction": 1
        }, {
            "name": "count2",
            "direction": -1
        }, {
            "name": "count3",
            "direction": -1
        }, {
            "name": "_id",
            "direction": -1
        }]
    }]
}

but it does not return anything, if I remove the $match section, it count on all the documents, and not only the last hour.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ccakes picture ccakes  路  3Comments

susodapop picture susodapop  路  3Comments

brylie picture brylie  路  3Comments

koooge picture koooge  路  3Comments

arikfr picture arikfr  路  4Comments