Search code examples
mongodbfiltermongodb-querymongodb-charts

MongoDB Embedded Chart filter


I am having trouble with applying MongoDB filter (the optional filters that we leave for end-user to apply). I'm using an Iframe option to show charts.

when I add an integer-based filter it works fine and returns me a number of users

eg : (those users that age is greater than 50)

filter = { "age": { $gt: 50 } }

But when I apply _id based filter it gives me 0

eg Those users that parentId match with given id

filter = { "parent_id" :  6t94f5c7webccea2c3e3d6856 }

I also check this way

filter = { "parent_id" :  ObjectId("6t94f5c7webccea2c3e3d6856") }

but non of them work.

here is my document look like

`{_id : ObjectId("5fe081a0689bdf07a365ddbf"), city: "Pakistan", parent_id : ObjectId("6t94f5c7webccea2c3e3d6856"), Age : 50, Name : "Test" }`

Thanks.


Solution

  • I found no issue with you query except spacing issue I used filters like that, and they are working fine for me, please recheck your params and try to identify any missing thing there hope it helps
    filter = { "your parent id " : ObjectId("mongoId") }