I have a document as:
{
'name':'XYZ',
'address':'Street 21',
'phone': {
'home': [123456, 456123]
},
'qualification': {
'primary': [
['AB','75'],
['CD','80'],
['EF','50']
]
}
}
Simple query would be like:
n = collection.find({'name':'XYZ'})
I can fetch documents using a list on the 'phone.home'
subdocument key like this:
list1 = [123456]
n = collection.find({'phone.home':{'$in': list1}})
I am stuck on how to query the collection using the qualification
key. Suppose I have either 'AB' or '75' (only one of them at a time), I am not able to make up query, e.g I only have the following list1:
list1 = ['AB']
n = collection.find({'qualification.primary':{'$in':list1}})
This definitely is not giving me the desired result. Any guidance will be appreciated!
Use
$elemMatch
two times query as :