Reputation: 1128
I got these documents:
I have to search for a friend in the friend list so what I got is:
$users->find(array('_id' => $userId, 'friendList.name' => new MongoRegex('/' . strtolower($keyword) . '/'), array('friendList.name')));
The problem is that it will return all friendlist names, how can I just obtain the information about the "friend" I am trying to search?
Thanks for help already :)
Upvotes: 0
Views: 498
Reputation: 561
Please reference this documentation page. http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+Fields#RetrievingaSubsetofFields-RetrievingaSubrangeofArrayElements
There are ways to retrieve subsets of arrays, though I'm not sure this will help you.
Upvotes: 1
Reputation: 12402
You cannot do this in mongo, you can search for a particular element, but mongo will always return the whole array, so you have to extract the element yourself.
Upvotes: 1