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:
{"$match":
{"time_stamp":
{"$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:
java.io.StringReader@2a8753d; line: 37, column: 21]
The problem is obviously the first call to new ISODate().
I have found several (https://github.com/metabase/metabase/pull/4132; https://github.com/metabase/metabase/issues/3170) 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?
Unexpected character (’.’ (code 46)): was expecting comma to separate Array entries at
[Source:java.io.StringReader@13c6fd05; 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…
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.