$newemail, "pass-6ren">
gpt4 book ai didi

php - mongodb num_rows 相当于 php

转载 作者:可可西里 更新时间:2023-11-01 09:23:32 25 4
gpt4 key购买 nike

如何获取结果的数量,相当于 mongodb 中的 num_rows(mysqli)?

如果我有

$db->$dbName->find(array("email" => $newemail, "password" => $newpass));

检查符合此条件的结果数量的最佳方法是什么?

在 mysqli 中我会做类似的事情

$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();

关于php - mongodb num_rows 相当于 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12098647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com