Skip to content Skip to sidebar Skip to footer

How To Search Through A Mongodb Collection For Dictionary Keys Nested In Array

i have some data in a mongodb database collection (i know which collection so im only looking through the collection ) with documents that looks like this: { '_id' : ObjectId('52a

Solution 1:

You can use dot notation in your query keys to do this, using the $exists operator to just check for existence:

db.test.find({'files.IyzkmGh4YGD61Tc3TJjaEY17hDldH': {'$exists': 1}})

To find all docs that contain those files and remove them:

db.test.update(
    {'files.IyzkmGh4YGD61Tc3TJjaEY17hDldH': {'$exists': 1}},
    {'$pull': {'files': {'IyzkmGh4YGD61Tc3TJjaEY17hDldH': {'$exists': 1}}}},
    multi=True)

Post a Comment for "How To Search Through A Mongodb Collection For Dictionary Keys Nested In Array"