Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

count mongodb in php

Tags:

php

count

mongodb

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 :)

like image 812
Ahmed Avatar asked Oct 17 '25 19:10

Ahmed


1 Answers

The new driver does not implement $cursor->count() use $collection->count() instead

$collection->count($filter)

in your case: $filter = array('paid' => 'true')

like image 133
Albert s Avatar answered Oct 20 '25 08:10

Albert s



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!