I am trying to do the equivalent of MongoDB, which should return all users called Joe Bloggs, that have at least one address where the City is defined as London:
db.users.findOne() {
name : "Joe Bloggs",
addresses : [{city: "London"}]
}
Using the Kohana 3 PHP module Mango: https://github.com/Wouterrr/MangoDB
I can return results based on top level objects like so:
foreach(Mango::factory('users', array(
'name' => 'Joe Bloggs',
))->load(FALSE) as $user) {
}
But I can't work out how to return results based on objects in arrays, I have tried variations of:
foreach(Mango::factory('users', array(
'name' => 'Joe Bloggs',
'addresses' => array('city' => 'London'),
))->开发者_运维百科;load(FALSE) as $user) {
}
and:
foreach(Mango::factory('users', array(
'name' => 'Joe Bloggs',
'addresses.$.city' => 'London',
))->load(FALSE) as $user) {
}
I think I'm really close I'm just stuck at the last.
I'm not familiar with the library you are using, but from a shell you would simply do this:
db.users.find({"name" : "Joe Bloggs", "addresses.city" : "London"});
So most likely, what you are looking for is:
foreach(Mango::factory('users', array(
'name' => 'Joe Bloggs',
'addresses.city' => 'London',
))->load(FALSE) as $user) {
}
精彩评论