I have a collection in mongodb like this:
db.country_list.find().pretty()
{
"_id" : ObjectId("53917321ccbc96175d7a808b"),
"countries" : [
{
"countryName" : "Afghanistan",
"iso3" : "AFG",
"callingCode" : "93"
},
{
"countryName" : "Aland Islands",
"iso3" : "ALA",
"callingCode" : "358"
},
{
"countryName" : "Albania",
"iso3" : "ALB",
"callingCode" : "355"
}
]
}
like that i have 100 country details
i want to retrieve a country name where the calling code is 355.
I have tried like this
db.country_list.find({countries: {$elemMatch :{ 'callingCode':'355'} } } )
and like this
db.country_list.find({'countries.callingCode':'355'}).pretty()
but i am getting all records.How to get a specific record .Thanks in advance