Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401]

(no description)

File Size: 1134 lines (46 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Collection:: (39 methods):
  __construct()
  __debugInfo()
  __toString()
  aggregate()
  bulkWrite()
  count()
  countDocuments()
  createIndex()
  createIndexes()
  deleteMany()
  deleteOne()
  distinct()
  drop()
  dropIndex()
  dropIndexes()
  estimatedDocumentCount()
  explain()
  find()
  findOne()
  findOneAndDelete()
  findOneAndReplace()
  findOneAndUpdate()
  getCollectionName()
  getDatabaseName()
  getManager()
  getNamespace()
  getReadConcern()
  getReadPreference()
  getTypeMap()
  getWriteConcern()
  insertMany()
  insertOne()
  listIndexes()
  mapReduce()
  replaceOne()
  updateMany()
  updateOne()
  watch()
  withOptions()


Class: Collection  - X-Ref

__construct(Manager $manager, $databaseName, $collectionName, array $options = [])   X-Ref
Constructs new Collection instance.

This class provides methods for collection-specific operations, such as
CRUD (i.e. create, read, update, and delete) and index management.

Supported options:

* readConcern (MongoDB\Driver\ReadConcern): The default read concern to
use for collection operations. Defaults to the Manager's read concern.

* readPreference (MongoDB\Driver\ReadPreference): The default read
preference to use for collection operations. Defaults to the Manager's
read preference.

* typeMap (array): Default type map for cursors and BSON documents.

* writeConcern (MongoDB\Driver\WriteConcern): The default write concern
to use for collection operations. Defaults to the Manager's write
concern.

param: Manager $manager        Manager instance from the driver
param: string  $databaseName   Database name
param: string  $collectionName Collection name
param: array   $options        Collection options

__debugInfo()   X-Ref
Return internal properties for debugging purposes.

return: array

__toString()   X-Ref
Return the collection namespace (e.g. "db.collection").

return: string

aggregate(array $pipeline, array $options = [])   X-Ref
Executes an aggregation framework pipeline on the collection.

Note: this method's return value depends on the MongoDB server version
and the "useCursor" option. If "useCursor" is true, a Cursor will be
returned; otherwise, an ArrayIterator is returned, which wraps the
"result" array from the command response document.

param: array $pipeline List of pipeline operations
param: array $options  Command options
return: Traversable

bulkWrite(array $operations, array $options = [])   X-Ref
Executes multiple write operations.

param: array[] $operations List of write operations
param: array   $options    Command options
return: BulkWriteResult

count($filter = [], array $options = [])   X-Ref
Gets the number of documents matching the filter.

param: array|object $filter  Query by which to filter documents
param: array        $options Command options
return: integer

countDocuments($filter = [], array $options = [])   X-Ref
Gets the number of documents matching the filter.

param: array|object $filter  Query by which to filter documents
param: array        $options Command options
return: integer

createIndex($key, array $options = [])   X-Ref
Create a single index for the collection.

param: array|object $key     Document containing fields mapped to values,
param: array        $options Index and command options
return: string The name of the created index

createIndexes(array $indexes, array $options = [])   X-Ref
Create one or more indexes for the collection.

Each element in the $indexes array must have a "key" document, which
contains fields mapped to an order or type. Other options may follow.
For example:

$indexes = [
// Create a unique index on the "username" field
[ 'key' => [ 'username' => 1 ], 'unique' => true ],
// Create a 2dsphere index on the "loc" field with a custom name
[ 'key' => [ 'loc' => '2dsphere' ], 'name' => 'geo' ],
];

If the "name" option is unspecified, a name will be generated from the
"key" document.

param: array[] $indexes List of index specifications
param: array   $options Command options
return: string[] The names of the created indexes

deleteMany($filter, array $options = [])   X-Ref
Deletes all documents matching the filter.

param: array|object $filter  Query by which to delete documents
param: array        $options Command options
return: DeleteResult

deleteOne($filter, array $options = [])   X-Ref
Deletes at most one document matching the filter.

param: array|object $filter  Query by which to delete documents
param: array        $options Command options
return: DeleteResult

distinct($fieldName, $filter = [], array $options = [])   X-Ref
Finds the distinct values for a specified field across the collection.

param: string       $fieldName Field for which to return distinct values
param: array|object $filter    Query by which to filter documents
param: array        $options   Command options
return: mixed[]

drop(array $options = [])   X-Ref
Drop this collection.

param: array $options Additional options
return: array|object Command result document

dropIndex($indexName, array $options = [])   X-Ref
Drop a single index in the collection.

param: string|IndexInfo $indexName Index name or model object
param: array            $options   Additional options
return: array|object Command result document

dropIndexes(array $options = [])   X-Ref
Drop all indexes in the collection.

param: array $options Additional options
return: array|object Command result document

estimatedDocumentCount(array $options = [])   X-Ref
Gets an estimated number of documents in the collection using the collection metadata.

param: array $options Command options
return: integer

explain(Explainable $explainable, array $options = [])   X-Ref
Explains explainable commands.

param: Explainable $explainable Command on which to run explain
param: array       $options     Additional options
return: array|object

find($filter = [], array $options = [])   X-Ref
Finds documents matching the query.

param: array|object $filter  Query by which to filter documents
param: array        $options Additional options
return: Cursor

findOne($filter = [], array $options = [])   X-Ref
Finds a single document matching the query.

param: array|object $filter  Query by which to filter documents
param: array        $options Additional options
return: array|object|null

findOneAndDelete($filter, array $options = [])   X-Ref
Finds a single document and deletes it, returning the original.

The document to return may be null if no document matched the filter.

param: array|object $filter  Query by which to filter documents
param: array        $options Command options
return: array|object|null

findOneAndReplace($filter, $replacement, array $options = [])   X-Ref
Finds a single document and replaces it, returning either the original or
the replaced document.

The document to return may be null if no document matched the filter. By
default, the original document is returned. Specify
FindOneAndReplace::RETURN_DOCUMENT_AFTER for the "returnDocument" option
to return the updated document.

param: array|object $filter      Query by which to filter documents
param: array|object $replacement Replacement document
param: array        $options     Command options
return: array|object|null

findOneAndUpdate($filter, $update, array $options = [])   X-Ref
Finds a single document and updates it, returning either the original or
the updated document.

The document to return may be null if no document matched the filter. By
default, the original document is returned. Specify
FindOneAndUpdate::RETURN_DOCUMENT_AFTER for the "returnDocument" option
to return the updated document.

param: array|object $filter  Query by which to filter documents
param: array|object $update  Update to apply to the matched document
param: array        $options Command options
return: array|object|null

getCollectionName()   X-Ref
Return the collection name.

return: string

getDatabaseName()   X-Ref
Return the database name.

return: string

getManager()   X-Ref
Return the Manager.

return: Manager

getNamespace()   X-Ref
Return the collection namespace.

return: string

getReadConcern()   X-Ref
Return the read concern for this collection.

return: ReadConcern

getReadPreference()   X-Ref
Return the read preference for this collection.

return: ReadPreference

getTypeMap()   X-Ref
Return the type map for this collection.

return: array

getWriteConcern()   X-Ref
Return the write concern for this collection.

return: WriteConcern

insertMany(array $documents, array $options = [])   X-Ref
Inserts multiple documents.

param: array[]|object[] $documents The documents to insert
param: array            $options   Command options
return: InsertManyResult

insertOne($document, array $options = [])   X-Ref
Inserts one document.

param: array|object $document The document to insert
param: array        $options  Command options
return: InsertOneResult

listIndexes(array $options = [])   X-Ref
Returns information for all indexes for the collection.

param: array $options
return: IndexInfoIterator

mapReduce(JavascriptInterface $map, JavascriptInterface $reduce, $out, array $options = [])   X-Ref
Executes a map-reduce aggregation on the collection.

param: JavascriptInterface $map     Map function
param: JavascriptInterface $reduce  Reduce function
param: string|array|object $out     Output specification
param: array               $options Command options
return: MapReduceResult

replaceOne($filter, $replacement, array $options = [])   X-Ref
Replaces at most one document matching the filter.

param: array|object $filter      Query by which to filter documents
param: array|object $replacement Replacement document
param: array        $options     Command options
return: UpdateResult

updateMany($filter, $update, array $options = [])   X-Ref
Updates all documents matching the filter.

param: array|object $filter  Query by which to filter documents
param: array|object $update  Update to apply to the matched documents
param: array        $options Command options
return: UpdateResult

updateOne($filter, $update, array $options = [])   X-Ref
Updates at most one document matching the filter.

param: array|object $filter  Query by which to filter documents
param: array|object $update  Update to apply to the matched document
param: array        $options Command options
return: UpdateResult

watch(array $pipeline = [], array $options = [])   X-Ref
Create a change stream for watching changes to the collection.

param: array $pipeline List of pipeline operations
param: array $options  Command options
return: ChangeStream

withOptions(array $options = [])   X-Ref
Get a clone of this collection with different options.

param: array $options Collection constructor options
return: Collection