I have a MongoDB Collection such as the Given Below
{ "IslamabadICT": { "campus_name": "Islamabad", "campus_province": "ICT" }, "KarachiSindh": { "campus_name": "Karachi", "campus_province": "Sindh" }, "LahorePunjab": { "campus_name": "Lahore", "campus_province": "Punjab" }, "PeshawarKPK": { "campus_name": "Peshawar", "campus_province": "KPK" } } and I want to Query all the documents where campus_name='Lahore'. I'm running the following command
db.campus.find({"campus_name":"Lahore"}).pretty() but it returns nothing. The version of MondoDB is 3.4 and I'm running mongo shell.
Any suggestions ?
Thanks in Advance
db.campus.find({"LahorePunjab.campus_name":"Lahore"}).pretty()campus_nameonly, it'll first try to find theLahorePunjabfield in document and If that fails it'll simply ignore thecampus_namefield value.