我有mongodb与数据库名称旅行和集合名称样本与数据如下

`{
    "_id": { id": "2344" },
    "places": { "destination": [ "singapore", "delhi" ] },
    "dt": { "date": "1434467400" }
},
{
    "_id": { id": "2345" },
    "places": { "destination": [ "singapore", "delhi" ] },
    "dt": { "date": "1434467445" }
},
{
    "_id": { "id": "2354" },
    "places": { "code": "7856", "source": [ "beijing", "singapore" ], "destination": [ "newyork", "landon", "sidney" ] },
    "dt": { "date": "1434589338" }
}`

我写了monogdb聚合函数来查找地方的数量

`db.sample.aggregate([{$group : {_id : "$places", count : {$sum : 1}}}, {$sort: {count: 1}}])`

显示结果为

{ "_id" : { "destination" : [ "singapore", "delhi" ] }, "count" : 2 } \
  { "_id" : { "code" : "7856", "source" : [ "beijing", "singapore" ], "destination
" : [ "newyork", "landon", "sidney" ] }, "count" : 1 }

通过分组地点为每个地方提供计数 .

我有这两个要求

  • 我想在php中使用mongodb连接编写此查询

  • 如果可能的话我想根据场内的代码或来源或目的地来计算 .

thanx提前帮助..