문제

db.users.aggregate(
    {$match : 
        {"_id" : ObjectId("50f69176904e1d66affec20d")}
    }, 
    {$unwind : "$connections"}, 
    {$match : 
        {$or : [
            {"connections.users" : {$exists : false}}, 
            {"connections.users.id" : "50f651b8b58bba7fbec2f223"}
        ]}},
    {$group : {_id : "$connections.group"}}
)

Here I am finding the group names in which specific user exists. I am getting the correct result in mongodb shell. Now I have to use it in the lithium framework. Please help me with the command. For collection structure, see this link : http://pastebin.com/P8uMw9cj

도움이 되었습니까?

해결책 2

You should read Tom Maiaroto's article "MongoDB Aggregation of all Shapes and Sizes"

It covers Map/Reduce, Grouping and The New Aggregation Framework

다른 팁

You can run arbitrary commands like this:

$files = Files::connection()->connection->command(array("geoNear" => "fs.files", "near" => $coords, "maxDistance" => 1));

You would use Users::connection() obviously, but there are also some improvements in aggregation being worked on, though not sure if they are in the master branch.

You can also see a demo app with aggregation here: https://github.com/jmikola/li3-mongodb-aggregation-demo/blob/master/app/controllers/DemoController.php that should help you get going.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top