Docs Menu

Docs HomePHP Library Manual

MongoDB\Collection Class

On this page

  • Definition
  • Type Map Limitations
  • Methods
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\\Client or MongoDB\\Database classes. A collection may also be cloned from an existing MongoDB\\Collection object via the withOptions() method.

MongoDB\\Collection supports the readConcern, readPreference, typeMap, and writeConcern options. If you omit an option, the collection inherits the value from the Manager constructor argument or the Client or Database object used to select the collection.

Operations within the MongoDB\\Collection class inherit the collection's options.

The aggregate (when not using a cursor), distinct, and findAndModify helpers do not support a typeMap option due to a driver limitation. The aggregate(), distinct(), findOneAndReplace(), findOneAndUpdate(), and findOneAndDelete() methods return BSON documents as stdClass objects and BSON arrays as arrays.

←  MongoDB\Database::withOptions()MongoDB\Collection::__construct() →