count mongodb in php
11,939
The new driver does not implement $cursor->count()
use $collection->count()
instead
$collection->count($filter)
in your case: $filter = array('paid' => 'true')
Author by
Ahmed
Updated on June 04, 2022Comments
-
Ahmed almost 2 years
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"
this is my try
<?php $connection = new MongoClient(); $collection = $connection->Ahmed->user; $cursor = $collection->find(); var_dump($collection->count()); var_dump($collection->count($cursor->paid=>"true"))); ?>
if there is an expert in mongo could help, thanks :)