I have a Document setup like this:
Users
{
_id : '',
name : '',
friends : [
{
'name' : '',
'email' : '',
'age' : ''
}
]
}
I'm trying to select a single friend from within the friends array by email, while only returning that specific object.
Any suggestions how to do this?
Thanks!
db.mytest.find({'friends.email':'abhi2'},{friends : {$elemMatch : {email : 'abhi2'}}}).pretty()
Or
db.mytest.find({'_id':'a'},{friends : {$elemMatch : {name : 'abhi2'}}}).pretty()
For more details, look this doc : http://docs.mongodb.org/manual/reference/projection/elemMatch/