I am working on mongoldb database, I am actually quite new to this database, I have a collection of contacts and I want to get individual data through mongo query.
Contacts Collection
[{
"_id": "57cd2f6c3966037787ce9550",
"contact": [{
"id": "457899979",
"fullname": "Abcd Hello",
"phonenumber": "123575784565",
"currentUserid": "123456789"
}, {
"id": "7994949849",
"fullname": "Keyboard Mouse",
"phonenumber": "23658974262",
"currentUserid": "123456789"
}, {
"id": "7848848885",
"fullname": "Test Xyz",
"phonenumber": "87556699632",
"currentUserid": "123456789"
}]
}, {
"_id": "57cd2fe02c40b97791b39fe3",
"contact": [{
"id": "457899979",
"fullname": "iPad",
"phonenumber": "85632889714",
"currentUserid": "789456123"
}, {
"id": "7994949849",
"fullname": "Cool",
"phonenumber": "33698777523",
"currentUserid": "789456123"
}]
}]
Mongo Query
db.friendslist.find({"currentUserid" : "789456123"})
But this query fetching empty results, I want to fetch the list of contacts of currentUserid : 789456123.
Please kindly go through my post and suggest me some solution.
Found Solution
db.friendslist.find({ "contact": { "$elemMatch": { "currentUserid" : "789456123" } } }).pretty()