在PHP中计数mongodb [英] count mongodb in php
本文介绍了在PHP中计数mongodb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个集合用户,该用户具有2个参数(用户名,已付费),用户名也是一个字符串,而付费也是一个字符串,我应该计算有多少个用户使用了参数paid ="true"
I have a collection user which has 2 parameters (Username,paid), username is a string and paid is a string too, i should count how many users with the parameter paid="true"
这是我的尝试
<?php
$connection = new MongoClient();
$collection = $connection->Ahmed->user;
$cursor = $collection->find();
var_dump($collection->count());
var_dump($collection->count($cursor->paid=>"true")));
?>
如果mongo的专家可以提供帮助,谢谢:)
if there is an expert in mongo could help, thanks :)
推荐答案
新驱动程序未实现$cursor->count()
,而使用$collection->count()
代替
The new driver does not implement $cursor->count()
use $collection->count()
instead
$collection->count($filter)
以您的情况为例:$filter = array('paid' => 'true')
这篇关于在PHP中计数mongodb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文