Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native MongoDB queries don't work if they contain ISODate() calls #3170

Closed
cwbeck opened this issue Aug 11, 2016 · 7 comments
Closed

Native MongoDB queries don't work if they contain ISODate() calls #3170

cwbeck opened this issue Aug 11, 2016 · 7 comments

Comments

@cwbeck
Copy link

cwbeck commented Aug 11, 2016

Query fails to run: (MongoDB)

[
  {
    "$match": {
      "hour": {
        "$gte": ISODate("2016-08-09T00:00:00Z")
      }
    }
  },
  {
    "$group": {
      "_id": {
        "year": {"$year": "$hour"},
        "month": {"$month": "$hour"}
      },
      "count": {
        "$sum": "$count"
      }
    }
  }
]
Unrecognized token 'ISODate': was expecting 'null', 'true', 'false' or NaN at [Source: java.io.StringReader@2b0b4b64; line: 6, column: 24]
@camsaul camsaul added the Type:Bug Product defects label Aug 15, 2016
@camsaul camsaul self-assigned this Aug 15, 2016
@camsaul camsaul modified the milestones: 0.19.2, 0.20.0 Aug 15, 2016
@camsaul
Copy link
Member

camsaul commented Aug 15, 2016

@cwbeck it looks like Metabase is trying to parse your MongoDB query as JSON (which works in most cases). We need to skip parsing and just pass the query string in directly because as this example shows Mongo aggregation pipeline queries are not necessarily strict JSON.

@camsaul camsaul changed the title MongoDB ISOData - Metabase Query Builder Issue Don't try to parse native MongoDB queries as JSON Aug 15, 2016
@cwbeck
Copy link
Author

cwbeck commented Aug 16, 2016

@camsaul thanks for the update. I'll take a look shortly

@camsaul camsaul changed the title Don't try to parse native MongoDB queries as JSON Native MongoDB queries don't work if they contain function calls Aug 30, 2016
@camsaul
Copy link
Member

camsaul commented Aug 30, 2016

So as far as I can tell there is no easy way to handle this situation given our current setup with Monger (our Mongo library). I've opened an issue upstream here: michaelklishin/monger#143

So until we have time to roll our own Mongo library for Clojure that handles our needs I'm going to have to mark this as a limitation 💔

@camsaul camsaul removed this from the 0.20.0 milestone Aug 30, 2016
@camsaul camsaul removed their assignment Sep 10, 2016
@Compuabhi
Copy link

Compuabhi commented Sep 20, 2016

@camsaul I was dealing with MongoDB native queries in metabase. In sql, one can add query parameters using {{var_name}}. What is the format for MongoDB query parameters? Using same format was throwing errors that "It is expecting double-quote to start field name. Whether this feature has been added or not?

@camsaul camsaul removed the Type:Bug Product defects label Jan 5, 2017
@camsaul camsaul changed the title Native MongoDB queries don't work if they contain function calls Native MongoDB queries don't work if they contain ISODate() calls Jan 11, 2017
@camsaul camsaul self-assigned this Jan 11, 2017
@camsaul camsaul modified the milestones: 0.23.0, 0.22.1 Jan 11, 2017
@camsaul
Copy link
Member

camsaul commented Jan 13, 2017

Fixed by #4132

@camsaul camsaul closed this as completed Jan 13, 2017
@daorren
Copy link

daorren commented Jun 28, 2019

WARNING: below is outdated, and using ISODate("2018-06-21") should be OK, which should be documented

try it out in pull/4132 test

[
    {
      "$match": {"$and": [
          {"logType": "ClickGlobalNavBtn"},
          {"target": "Mail"},
          {"created": {"$gte": ["___ISODate", "2018-06-21"]}}
      ]}
    },
    {
      "$group": {"_id": "$target", "count": {"$sum": 1}}
    }
]

@mhdali93
Copy link

Not working for me, it is showing: No results!
This may be the answer you’re looking for. If not, try removing or changing your filters to make them less specific.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants