i have the sample JSON as below.
{
"subscriber": {
"id": "123",
"custom_field1": "0",
"custom_field2": "0"
},
"subscriptions": [{
"12": {
"subs_id": "111",
"state": "5",
}
}, {
"13": {
"subs_id": "222",
"state": "8",
}, {
"14": {
"subs_id": "111",
"state": "8",
}
}]
}
I am able to query on Mongo DB like
db.testTable.find({"subscriber.id":"123"});
And i am able to get the results too using the above query.
Now i want to filter the data on subscriptions array which consist of "subs_id" = "111".
I tried like below
db.testTable.find({"subscriptions.subs_id":"111"});
which is not giving me results. Can some one suggest me how to do this.
Note: I understand that its in List< Map < String, Map < String, String > > > format and i am querying on value portion of Map object. But not able to get any clue how to fetch the results.
{"subs_key":"12", "subs_id": "111", "state": "5", }and you can find the subscription usingdb.testTable.find({"subscriber.id":"123", "subscriptions.subs_id":"111"},{"subscriptions.$":1);12in your example.db.testTable.find({"subscriptions.12.subs_id":"111"})works.