I want to setup a cached query of MongoDB so that I can use a Query Result to analyze the data in different ways.

My MongoDB is way too large for this so I want to setup an automatic refresh to grab only the last 30 days prior to today.

{
    "collection": "EventTrack",
    "aggregate": [
        {
            "$match": {
                "$and": [
                    {
                        "EventType": "Click"
                    },{
                        "AssemblyId": {
                            "$gt": 0
                        }
                    },{
                        "EntryDate":{
                            "$gte": {
                               "$humanTime": "new Date((new Date().getTime() - (30 * 24 * 60 * 60 * 1000)))"
                            }
                        }
                    }
                ]
            }
        }

How do I achieve this?

Easy, humanTime is meant to make this easy:

{
    "collection": "EventTrack",
    "aggregate": [
        {
            "$match": {
                "$and": [
                    {
                        "EventType": "Click"
                    },{
                        "AssemblyId": {
                            "$gt": 0
                        }
                    },{
                        "EntryDate":{
                            "$gte": {
                               "$humanTime": "last 30 days"
                            }
                        }
                    }
                ]
            }
        }

Keep in mind that you can’t use Python/JS syntax in Redash queries. It will always raise errors.

FYI: the “tips and tricks” area of this forum is not for Q&A. It’s to show off cool ways of using Redash. I moved your question into the “support” area for more visibility.

1 Like