mongodb num_rows等效的php [英] mongodb num_rows equivalent php
本文介绍了mongodb num_rows等效的php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何获得等于mongodb
中的num_rows
(mysqli)的结果数?
how can i get the number of results, equivalent to num_rows
(mysqli) in mongodb
?
如果我有
$db->$dbName->find(array("email" => $newemail, "password" => $newpass));
检查符合此条件的结果数量的最佳方法是什么?
在mysqli中,我会做类似的事情
what is the best way to check the number of results that match this criteria?
in mysqli i would do something like
$sql = "SELECT id FROM table WHERE email='%s' AND password='%s'";
$query = sprintf($sql, $newemail, $newpass);
$result = $conn->query($query);
$rows = $result->num_rows;
推荐答案
就像这样,我认为:
$collection = $connection->myDB->myCollection;
$cursor = $collection->find(array("email" => $newemail, "password" => $newpass));
$nResults = $cursor->count();
这篇关于mongodb num_rows等效的php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文