Mongodb PHP根据特定字段查找行数

I am trying to display the count of items based on a category for a specific user email. This is my PHP code for the following

$email = $_SESSION['loggedInUserEmail'];

//Connect to MongoDB
$mongoClient = new MongoClient();

//Select a database
$db = $mongoClient->finchest;

$CheckEmail = [
    "CustEmail" => $email,
];


$collection = $db->History;

$Criteria = array("Category" => "Fish Skins");
$returnVal = $collection->find($CheckEmail)->count($Criteria);
echo $returnVal;

This code gives me the following error

Warning: MongoCursor::count() expects parameter 1 to be boolean, array given in C:\www\FinChest\PHPecommend.php on line 89

Please help me solve it, THANKS A TON.

doude1917
doude1917 我在我的代码中找到了问题。我应该在$CheckEmail数组中添加两个条件,然后只使用count()。非常感谢。@Mani
一年多之前 回复
dongpa6867
dongpa6867 你在尝试使用$Criteria参数做什么?试试这个$returnVal=$collection->find($CheckEmail)->count();
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐