php mongocollection,PHP: MongoCollection::aggregate - Manual

示例 #4 MongoCollection::aggregate() with command options

To return information on how the pipeline will be processed we use the

explain command option:

$m= newMongoClient;$c=$m->selectDB("test")->selectCollection("zips");$pipeline= array(

array('$group'=> array('_id'=>'$state','totalPop'=> array('$sum'=>'$pop'),

),

),

array('$match'=> array('totalPop'=> array('$gte'=>10*1000*1000)

)

),

array('$sort'=> array("totalPop"=> -1),

),

);$options= array("explain"=>true);$out=$c->aggregate($pipeline,$options);var_dump($out);?>

以上例程的输出类似于:

array(2) {

["stages"]=>

array(4) {

[0]=>

array(1) {

["$cursor"]=>

array(3) {

["query"]=>

array(0) {

}

["fields"]=>

array(3) {

["pop"]=>

int(1)

["state"]=>

int(1)

["_id"]=>

int(0)

}

["plan"]=>

array(4) {

["cursor"]=>

string(11) "BasicCursor"

["isMultiKey"]=>

bool(false)

["scanAndOrder"]=>

bool(false)

["allPlans"]=>

array(1) {

[0]=>

array(3) {

["cursor"]=>

string(11) "BasicCursor"

["isMultiKey"]=>

bool(false)

["scanAndOrder"]=>

bool(false)

}

}

}

}

}

[1]=>

array(1) {

["$group"]=>

array(2) {

["_id"]=>

string(6) "$state"

["totalPop"]=>

array(1) {

["$sum"]=>

string(4) "$pop"

}

}

}

[2]=>

array(1) {

["$match"]=>

array(1) {

["totalPop"]=>

array(1) {

["$gte"]=>

int(10000000)

}

}

}

[3]=>

array(1) {

["$sort"]=>

array(1) {

["sortKey"]=>

array(1) {

["totalPop"]=>

int(-1)

}

}

}

}

["ok"]=>

float(1)

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值