Writing custom query for MongoDB

Hi,

New to metabase. Can someone help me figure out how do I write a custom query for MongoDb. I am able to use GUI to create queries and get results but not able to figure out how to write custom query in the query editor.

Thanks!

We don’t currently have that feature.

I’ve opened a place to collect community interest, and if you could chime in on https://github.com/metabase/metabase/issues/2072 it would help us get a sense of how many people need this.

Are you able to filter e.g. on a column? I only get a “select” which is not complete (e.g. on user name)

@sameer

While it’s not possible to use the ‘Custom Filters’, you can still write custom queries - with a slight variation on Mongos ‘Aggregation’ syntax.

For example, here’s what the syntax looks like from a mongodb client:

db.receivers.aggregate( [
   { $match: { email: {$ne : ""} } },
   {
     $group: {
        _id: "$publicIdentifier",
        email: {$push: '$email'}
     }
   }
] )

And the same query within Metabase (after you select the database and collection:) (just after adding double-quotes)

[{"$match": { "email": {"$ne" : ""} } },
   {
     "$group": {
        "_id": "$publicIdentifier",
        "email": {"$push": "$email"}
     }
   }]

Hi @kramer1346
I don’t use MongoDB, but it looks like you’re not using the latest Metabase release 0.31.2
But there are some limitations with the different database drivers.
https://github.com/metabase/metabase/issues/7442