Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用php实现mongodb聚合查询_Php_Mongodb_Aggregation Framework - Fatal编程技术网

用php实现mongodb聚合查询

用php实现mongodb聚合查询,php,mongodb,aggregation-framework,Php,Mongodb,Aggregation Framework,我有数据库名为travel和collection名为sample的mongodb,数据如下 `{ "_id": { id": "2344" }, "places": { "destination": [ "singapore", "delhi" ] }, "dt": { "date": "1434467400" } }, { "_id": { id": "2345" }, "places": { "destination": [ "singapore",

我有数据库名为travel和collection名为sample的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提前获得帮助。

    你好,Surendra,欢迎使用Stack Overflow。很抱歉不得不这么说,但是你的问题并不适合这个网站。如果您根本不知道如何编写查询mongodb的php,那么您需要找到合适的教程或课程。如果您正在编写代码,并且遇到了需要帮助的特定问题,并且可以显示无法正常工作的代码,那么您可以返回堆栈溢出。请看一看以获得一些指导。嗨,VinceBowdren,谢谢你的建议。我会尽我最大的努力回答适当的问题。