Reputation: 1128
I got these documents:
I need to search in php (mongodb) for a friend, so name in friendList. How can I do this?
Upvotes: 0
Views: 318
Reputation: 12420
In the shell you'd do it like this:
> db.people.find({ "friendList.name" : /Joe/})
UPDATE: a proof:
> db.person.insert({name : 'scatman', friendList : [ {name: 'joe'}, {name: 'nick'} ]});
> db.person.findOne()
{
"_id" : ObjectId("4f155cafef7b8b0317a8ad17"),
"name" : "scatman",
"friendList" : [
{
"name" : "joe"
},
{
"name" : "nick"
}
]
}
> db.person.findOne({"friendList.name" : /jo/})
{
"_id" : ObjectId("4f155cafef7b8b0317a8ad17"),
"name" : "scatman",
"friendList" : [
{
"name" : "joe"
},
{
"name" : "nick"
}
]
}
>
Upvotes: 3