开发者

Return results by array object value

开发者 https://www.devze.com 2023-02-15 23:27 出处:网络
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:

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) {
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号