2015-03-13 77 views
0

我正在开发使用mongodb & PHP的RESTful API。我使用find函数根据条件检索记录。查找函数返回我mongocursor我已经通过foreach循环迭代到Mongodb:如何用mongocursor检查find函数的计数?

$teams = $mongoDb2->find(array('team_maker_id' => (string)$userid)); 
$count = count($teams); 

我曾尝试计数($队)获得的数据,但它返回我1即使它不包含任何数据。

如何获取$队中的记录数?

回答

1

简单,你可以做以下

$teamsCount = $mongoDb2->find(array('team_maker_id' => (string)$userid))->count(); 

在$ teamsCount您将获得本&球队的数量,如果它不是0,那么你上面写的再次触发查询。

相关问题