Using a Cursor to Get All of the Documents
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:
<?php
$connection = new MongoClient();
$collection = $connection->database->collectionName;
$cursor = $collection->find();
foreach ( $cursor as $id => $value )
{
echo "$id: ";
var_dump( $value );
}
?>
See Also
The API documentation on MongoCollection::find() contains more information about finding data.
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- MongoDB
- Manual
- Making a Connection
- Getting a Database
- Getting A Collection
- Inserting a Document
- Finding Documents using MongoCollection::findOne
- Adding Multiple Documents
- Counting Documents in A Collection
- Using a Cursor to Get All of the Documents
- Setting Criteria for a Query
- Getting A Set of Documents With a Query
- Creating An Index
Коментарии
404 Not Found