Please wait while we load your page...


Latest Version [8.00202205221] Last Updated [May-22-2022]


PHP Manual [Using a Cursor to Get All of the Documents]

Protect Your Website Today

PHP Manual || Tutorial

In order to get all the documents in the collection, we will use MongoCollection::find(). The find() method returns a MongoCursor object which allows us to iterate over the set of documents that matched our query. So to query all of the documents and print them out:

= new MongoClient();
$collection $connection->database->collectionName;

$cursor $collection->find();
foreach ( 
$cursor as $id => $value )
"$id: ";
var_dump$value );
and that should print all 101 documents in the collection. $id is the _id field of a document (cast to a string) and $value is the document itself.

The API documentation on MongoCollection::find() contains more information about finding data.

PHP Manual || Tutorial