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

在这里,我找到了特定用户所在的组名。我在 mongodb shell 中得到了正确的结果。现在我必须在锂框架中使用它。请帮我执行命令。有关集合结构,请参阅此链接: http: //pastebin.com/P8uMw9cj

4

2 回答 2

1

您可以像这样运行任意命令:

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

您显然会使用 Users::connection(),但是聚合也有一些改进,尽管不确定它们是否在 master 分支中。

您还可以在此处查看带有聚合的演示应用程序:https ://github.com/jmikola/li3-mongodb-aggregation-demo/blob/master/app/controllers/DemoController.php应该可以帮助您开始。

于 2013-02-05T05:52:10.817 回答
0

您应该阅读 Tom Maiaroto 的文章“MongoDB Aggregation of all Shapes and Sizes”

它涵盖了 Map/Reduce、分组和新的聚合框架

于 2013-01-28T16:06:58.713 回答