I'm trying to query a MongoDB database to find all results which contains an specific ID:
My schema looks like this:
_id: xyz
ad_accounts: [{"name":"abc, "ads:{"campaings":[123, 4456, 574]}}]
I need to find all the results which contain 123 in "campaigns"
Here is a better image of the schema:
I've tried the following:
results = db.data.find({"ad_accounts.ads.campaigns": 123})
But it doesn't work since ad_accounts is an array, I've also tried with a loop:
for data in all_data:
for account in data['ad_accounts']:
if first_ad in account['ads']['campaigns]:
print("this is the one")
But I don't think it's the best.
Is there a built-in way to query nested data? Thanks