- Reference >
- MongoDB\Collection Class
MongoDB\Collection Class
On this page
Definition
-
MongoDB\Collection Provides methods for common operations on collections and documents, including CRUD operations and index management.
You can construct collections directly using the driver’s MongoDB\Driver\Manager class or select a collection from the library’s
MongoDB\ClientorMongoDB\Databaseclasses. A collection may also be cloned from an existingMongoDB\Collectionobject via thewithOptions()method.MongoDB\Collectionsupports the readConcern, readPreference, typeMap, and writeConcern options. If you omit an option, the collection inherits the value from the Manager constructor argument or theClientorDatabaseobject used to select the collection.Operations within the
MongoDB\Collectionclass inherit the collection’s options.
Type Map Limitations
The aggregate (when not using a cursor), distinct, and findAndModify helpers do not support atypeMapoption due to a driver limitation. Theaggregate(),distinct(),findOneAndReplace(),findOneAndUpdate(), andfindOneAndDelete()methods return BSON documents as stdClass objects and BSON arrays as arrays.
Methods
- MongoDB\Collection::__construct()
- MongoDB\Collection::aggregate()
- MongoDB\Collection::bulkWrite()
- MongoDB\Collection::count()
- MongoDB\Collection::countDocuments()
- MongoDB\Collection::createIndex()
- MongoDB\Collection::createIndexes()
- MongoDB\Collection::deleteMany()
- MongoDB\Collection::deleteOne()
- MongoDB\Collection::distinct()
- MongoDB\Collection::drop()
- MongoDB\Collection::dropIndex()
- MongoDB\Collection::dropIndexes()
- MongoDB\Collection::estimatedDocumentCount()
- MongoDB\Collection::explain()
- MongoDB\Collection::find()
- MongoDB\Collection::findOne()
- MongoDB\Collection::findOneAndDelete()
- MongoDB\Collection::findOneAndReplace()
- MongoDB\Collection::findOneAndUpdate()
- MongoDB\Collection::getCollectionName()
- MongoDB\Collection::getDatabaseName()
- MongoDB\Collection::getManager()
- MongoDB\Collection::getNamespace()
- MongoDB\Collection::getReadConcern()
- MongoDB\Collection::getReadPreference()
- MongoDB\Collection::getTypeMap()
- MongoDB\Collection::getWriteConcern()
- MongoDB\Collection::insertMany()
- MongoDB\Collection::insertOne()
- MongoDB\Collection::listIndexes()
- MongoDB\Collection::mapReduce()
- MongoDB\Collection::rename()
- MongoDB\Collection::replaceOne()
- MongoDB\Collection::updateMany()
- MongoDB\Collection::updateOne()
- MongoDB\Collection::watch()
- MongoDB\Collection::withOptions()