MongoDB\Collection Class
For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt
MongoDB\Collection Class
Definition
Provides methods for common operations on collections and documents, including CRUD operations and index management.
You can construct collections directly using the extension's MongoDB\Driver\Manager class or select a collection from the library's [MongoDB\Client](https://www.mongodb.com/docs/php-library/current/reference/class/mongodbclient.md#mongodb-phpclass-phpclass.MongoDB-Client or [MongoDB\Database](https://www.mongodb.com/docs/php-library/current/reference/class/mongodbdatabase.md#mongodb-phpclass-phpclass.MongoDB-Database classes. A collection may also be cloned from an existing [MongoDB\Collection](https://www.mongodb.com/docs/php-library/current/reference/class/mongodbcollection.md#mongodb-phpclass-phpclass.MongoDB-Collection object by using the [withOptions()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-withoptions.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--withOptions-- method.
[MongoDB\Collection](https://www.mongodb.com/docs/php-library/current/reference/class/mongodbcollection.md#mongodb-phpclass-phpclass.MongoDB-Collection supports the readConcern, readPreference, [typeMap](https://php.net/manual/en/mongodb.persistence.deserialization.php#mongodb.persistence.typemaps, and writeConcern options. If you omit an option, the collection inherits the value from the Manager constructor argument or the [Client](https://www.mongodb.com/docs/php-library/current/reference/class/mongodbclient.md#mongodb-phpclass-phpclass.MongoDB-Client or [Database](https://www.mongodb.com/docs/php-library/current/reference/class/mongodbdatabase.md#mongodb-phpclass-phpclass.MongoDB-Database object used to select the collection.
Operations within the [MongoDB\Collection](https://www.mongodb.com/docs/php-library/current/reference/class/mongodbcollection.md#mongodb-phpclass-phpclass.MongoDB-Collection class inherit the collection's options.
Methods
-
[
MongoDB\Collection::__construct()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection__construct.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--__construct-- -
[
MongoDB\Collection::aggregate()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-aggregate.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--aggregate-- -
[
MongoDB\Collection::bulkWrite()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-bulkwrite.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--bulkWrite-- -
[
MongoDB\Collection::count()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-count.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--count-- -
[
MongoDB\Collection::countDocuments()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-countdocuments.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--countDocuments-- -
[
MongoDB\Collection::createIndex()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-createindex.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--createIndex-- -
[
MongoDB\Collection::createIndexes()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-createindexes.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--createIndexes-- -
[
MongoDB\Collection::createSearchIndex()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-createsearchindex.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--createSearchIndex-- -
[
MongoDB\Collection::createSearchIndexes()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-createsearchindexes.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--createSearchIndexes-- -
[
MongoDB\Collection::deleteMany()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-deletemany.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--deleteMany-- -
[
MongoDB\Collection::deleteOne()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-deleteone.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--deleteOne-- -
[
MongoDB\Collection::distinct()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-distinct.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--distinct-- -
[
MongoDB\Collection::drop()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-drop.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--drop-- -
[
MongoDB\Collection::dropIndex()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-dropindex.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--dropIndex-- -
[
MongoDB\Collection::dropIndexes()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-dropindexes.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--dropIndexes-- -
[
MongoDB\Collection::dropSearchIndex()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-dropsearchindex.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--dropSearchIndex-- -
[
MongoDB\Collection::estimatedDocumentCount()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-estimateddocumentcount.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--estimatedDocumentCount-- -
[
MongoDB\Collection::explain()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-explain.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--explain-- -
[
MongoDB\Collection::find()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-find.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--find-- -
[
MongoDB\Collection::findOne()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-findone.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--findOne-- -
[
MongoDB\Collection::findOneAndDelete()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-findoneanddelete.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--findOneAndDelete-- -
[
MongoDB\Collection::findOneAndReplace()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-findoneandreplace.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--findOneAndReplace-- -
[
MongoDB\Collection::findOneAndUpdate()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-findoneandupdate.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--findOneAndUpdate-- -
[
MongoDB\Collection::getCollectionName()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-getcollectionname.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--getCollectionName-- -
[
MongoDB\Collection::getDatabaseName()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-getdatabasename.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--getDatabaseName-- -
[
MongoDB\Collection::getManager()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-getmanager.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--getManager-- -
[
MongoDB\Collection::getNamespace()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-getnamespace.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--getNamespace-- -
[
MongoDB\Collection::getReadConcern()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-getreadconcern.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--getReadConcern-- -
[
MongoDB\Collection::getReadPreference()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-getreadpreference.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--getReadPreference-- -
[
MongoDB\Collection::getTypeMap()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-gettypemap.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--getTypeMap-- -
[
MongoDB\Collection::getWriteConcern()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-getwriteconcern.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--getWriteConcern-- -
[
MongoDB\Collection::insertMany()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-insertmany.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--insertMany-- -
[
MongoDB\Collection::insertOne()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-insertone.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--insertOne-- -
[
MongoDB\Collection::listIndexes()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-listindexes.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--listIndexes-- -
[
MongoDB\Collection::listSearchIndexes()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-listsearchindexes.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--listSearchIndexes-- -
[
MongoDB\Collection::rename()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-rename.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--rename-- -
[
MongoDB\Collection::replaceOne()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-replaceone.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--replaceOne-- -
[
MongoDB\Collection::updateMany()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-updatemany.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--updateMany-- -
[
MongoDB\Collection::updateOne()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-updateone.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--updateOne-- -
[
MongoDB\Collection::updateSearchIndex()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-updatesearchindex.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--updateSearchIndex-- -
[
MongoDB\Collection::watch()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-watch.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--watch-- -
[
MongoDB\Collection::withOptions()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-withoptions.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--withOptions--
