randomKek
randomKek

Reputation: 1128

mongodb embedded objects search

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

Answers (2)

spf13
spf13

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

milan
milan

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

Related Questions