Custom mongodb query in metabase

Hi,
I'm using metabase and new in mongoDB. I've connected my database to metabase, and now I need to join 2 documents of mongoDB in metabase. The exact query that I've written in datagrip has data, but the same code in metabase faces bugs.
I've tried many things and did many search but I couldn't find any solution.
Could you please give me a sample which works on metabase?
thanks a lot

Any idea?!

Hi @ghazalak

Post "Diagnostic Info" from Admin > Troubleshooting.

It would probably be helpful if you posted your query.

What does "faces bugs" mean? Errors? If yes, then post the error.

Metabase does not support joins:
https://github.com/metabase/metabase/issues/9095 - upvote by clicking :+1: on the first post
With that being said, it's very inefficient to do joins on Mongo:
https://stackoverflow.com/questions/2350495/how-do-i-perform-the-sql-join-equivalent-in-mongodb

I've already upvoted that issue.
I've got this error:
readStartArray can only be called when CurrentBSONType is ARRAY, not when CurrentBSONType is DOCUMENT.
on this code:

{
   $lookup:
     {
       from: "plans",
       localField: "$plan",
       foreignField: "$id",
       as: "result"
     }
}

image

I also tried this one:
Object_storage.plans.aggregate([
{
$lookup:
{
from: "plans",
localField: :"$plan",
foreignField: "$id",
as: "result"
}
}
])

error:
JSON reader was expecting a value but found 'Object_storage'.

@ghazalak I guess it's something to do with your field types, as noted by the error returned (which comes from Mongo).
This works fine, when I run it on our Sample Dataset's Order table:

[{
   $lookup:
     {
       from: "products",
       localField: "product_id",
       foreignField: "id",
       as: "result"
     }
}]

Thank you so much, I should replace '{' with '[' at the beginning.