'How do you reference "current date" in a Metabase MongoDB native query?

I would like to use manual logic inside of a Metabase question. When referencing "Past 30 days" for example, the Metabase query builder can dynamically update the question to reference the current date. When converted to a native query, however, the dates convert to hard-coded dates eg. 2017-11-30. I've seen answers elsewhere suggesting "new Date()" etc but none of these will work within Metabase's native query editor. I'm looking for something like..

...
{
  "created_at": {"$gte": "new Date()"}
},
...

though this method does not work. Thanks in advance!



Solution 1:[1]

Using new Date()

As of v0.41, it seems like Metabase would accept the new Date() syntax and insert the server's date when writing it like so:

[{
    $group: {
        _id: new Date()
    }
}]

Proof of work on Metabase v0.41

new Date() query on Metabase working

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zachary Dahan