The common select count(*) syntax in relational SQL is very handy to get the number of records not the records itself. How to to this in MongoDB?

If all you want is get the total number of items matching the query, use the count() function.

 
$result = $collection->find(array('category' => 'book')).count();
echo $result;