Metabase fails on new ISODate() mongo native query

OS: Ubuntu 16.04
Metabase version: 0.29.3

I am running an aggregation pipeline for mongo, where I’m trying to look at all the datapoints in the past X days.
Due to the nature of the data, I need to run it in a JSON mongo query. The step that is failing looks like this:

    {"$lt": new ISODate(), 
     "$gte": new ISODate(new ISODate().setDate(new ISODate().getDate()-30))}}}

and I am getting the following error:

Unrecognized token 'new': was expecting 'null', 'true', 'false' or NaN at [Source:; line: 37, column: 21]

The problem is obviously the first call to new ISODate().

I have found several (; other github bug reports regarding this and they appear as fixed and merged, yet I cannot do it…

Am I doing something wrong, or is it actually a feature that’s not (yet) supported?

I’m not a MongoDB user myself, but searching for ISODate here gives several examples of MongoDB ISODate() queries without the new keyword. What happens if you drop the news in your query?

Good point and I have tried that too:

    {"$lt": ISODate(), 
     "$gte": ISODate(ISODate().setDate(ISODate().getDate()-30))

and I get the following error:

Unexpected character (’.’ (code 46)): was expecting comma to separate Array entries at
[; line: 37, column: 48]

It does not interpret “.” correctly, and that seems to happen with operations ("-") as well.
However, using just ISODate() does seem to work if I only have this matching code:

{"$lt": ISODate()}

but this is kind of useless, since I need a way to set dates relative to the present moment.
I’m sure I could hardcode the dates every time I need the query, but that defeats the purpose of making it automatic…

I am also having the same problem.
Did you find any solution for this?

I have a similar problem.

You can store any function in Mongodb. I used this to create a function that returns the current date and time and tried to call it from the metabase.

However, in order to execute any additional functions, you need to run db.loadServerScripts() to load the function.
I couldn’t do this with metabase, so I gave up.

Translated with (free version)

It still doesn't work.
I need it to set the date of today at midnight like

"dateString": ISODate().getFullYear() + "-" + (ISODate().getMonth() + 1) + "-" + ISODate().getDate() + "T00:00:00"

1 Like