Moodle PHP Documentation 4.1
Moodle 4.1.11 (Build: 20240610) (c8c84b4af18)
|
Public Member Functions | |
__construct (Manager $manager, string $databaseName, string $collectionName, array $options=[]) | |
Constructs new Collection instance. | |
__debugInfo () | |
Return internal properties for debugging purposes. | |
__toString () | |
Return the collection namespace (e.g. | |
aggregate (array $pipeline, array $options=[]) | |
Executes an aggregation framework pipeline on the collection. | |
bulkWrite (array $operations, array $options=[]) | |
Executes multiple write operations. | |
count ($filter=[], array $options=[]) | |
Gets the number of documents matching the filter. | |
countDocuments ($filter=[], array $options=[]) | |
Gets the number of documents matching the filter. | |
createIndex ($key, array $options=[]) | |
Create a single index for the collection. | |
createIndexes (array $indexes, array $options=[]) | |
Create one or more indexes for the collection. | |
deleteMany ($filter, array $options=[]) | |
Deletes all documents matching the filter. | |
deleteOne ($filter, array $options=[]) | |
Deletes at most one document matching the filter. | |
distinct (string $fieldName, $filter=[], array $options=[]) | |
Finds the distinct values for a specified field across the collection. | |
drop (array $options=[]) | |
Drop this collection. | |
dropIndex ($indexName, array $options=[]) | |
Drop a single index in the collection. | |
dropIndexes (array $options=[]) | |
Drop all indexes in the collection. | |
estimatedDocumentCount (array $options=[]) | |
Gets an estimated number of documents in the collection using the collection metadata. | |
explain (Explainable $explainable, array $options=[]) | |
Explains explainable commands. | |
find ($filter=[], array $options=[]) | |
Finds documents matching the query. | |
findOne ($filter=[], array $options=[]) | |
Finds a single document matching the query. | |
findOneAndDelete ($filter, array $options=[]) | |
Finds a single document and deletes it, returning the original. | |
findOneAndReplace ($filter, $replacement, array $options=[]) | |
Finds a single document and replaces it, returning either the original or the replaced document. | |
findOneAndUpdate ($filter, $update, array $options=[]) | |
Finds a single document and updates it, returning either the original or the updated document. | |
getCollectionName () | |
Return the collection name. | |
getDatabaseName () | |
Return the database name. | |
getManager () | |
Return the Manager. | |
getNamespace () | |
Return the collection namespace. | |
getReadConcern () | |
Return the read concern for this collection. | |
getReadPreference () | |
Return the read preference for this collection. | |
getTypeMap () | |
Return the type map for this collection. | |
getWriteConcern () | |
Return the write concern for this collection. | |
insertMany (array $documents, array $options=[]) | |
Inserts multiple documents. | |
insertOne ($document, array $options=[]) | |
Inserts one document. | |
listIndexes (array $options=[]) | |
Returns information for all indexes for the collection. | |
mapReduce (JavascriptInterface $map, JavascriptInterface $reduce, $out, array $options=[]) | |
Executes a map-reduce aggregation on the collection. | |
rename (string $toCollectionName, ?string $toDatabaseName=null, array $options=[]) | |
Renames the collection. | |
replaceOne ($filter, $replacement, array $options=[]) | |
Replaces at most one document matching the filter. | |
updateMany ($filter, $update, array $options=[]) | |
Updates all documents matching the filter. | |
updateOne ($filter, $update, array $options=[]) | |
Updates at most one document matching the filter. | |
watch (array $pipeline=[], array $options=[]) | |
Create a change stream for watching changes to the collection. | |
withOptions (array $options=[]) | |
Get a clone of this collection with different options. | |
MongoDB\Collection::__construct | ( | Manager | $manager, |
string | $databaseName, | ||
string | $collectionName, | ||
array | $options = [] ) |
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:
Manager | $manager | Manager instance from the driver |
string | $databaseName | Database name |
string | $collectionName | Collection name |
array | $options | Collection options |
InvalidArgumentException | for parameter/option parsing errors |
MongoDB\Collection::__debugInfo | ( | ) |
Return internal properties for debugging purposes.
array |
MongoDB\Collection::__toString | ( | ) |
Return the collection namespace (e.g.
"db.collection").
string |
MongoDB\Collection::aggregate | ( | array | $pipeline, |
array | $options = [] ) |
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.
array | $pipeline | List of pipeline operations |
array | $options | Command options |
Traversable |
UnexpectedValueException | if the command response was malformed |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::bulkWrite | ( | array | $operations, |
array | $options = [] ) |
Executes multiple write operations.
array[] | $operations | List of write operations |
array | $options | Command options |
BulkWriteResult |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::count | ( | $filter = [], | |
array | $options = [] ) |
Gets the number of documents matching the filter.
array | object | $filter | Query by which to filter documents |
array | $options | Command options |
integer |
UnexpectedValueException | if the command response was malformed |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::countDocuments | ( | $filter = [], | |
array | $options = [] ) |
Gets the number of documents matching the filter.
array | object | $filter | Query by which to filter documents |
array | $options | Command options |
integer |
UnexpectedValueException | if the command response was malformed |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::createIndex | ( | $key, | |
array | $options = [] ) |
Create a single index for the collection.
array | object | $key | Document containing fields mapped to values, which denote order or an index type |
array | $options | Index and command options |
string | The name of the created index |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::createIndexes | ( | array | $indexes, |
array | $options = [] ) |
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.
array[] | $indexes | List of index specifications |
array | $options | Command options |
string[] | The names of the created indexes |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::deleteMany | ( | $filter, | |
array | $options = [] ) |
Deletes all documents matching the filter.
array | object | $filter | Query by which to delete documents |
array | $options | Command options |
DeleteResult |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::deleteOne | ( | $filter, | |
array | $options = [] ) |
Deletes at most one document matching the filter.
array | object | $filter | Query by which to delete documents |
array | $options | Command options |
DeleteResult |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::distinct | ( | string | $fieldName, |
$filter = [], | |||
array | $options = [] ) |
Finds the distinct values for a specified field across the collection.
string | $fieldName | Field for which to return distinct values |
array | object | $filter | Query by which to filter documents |
array | $options | Command options |
array |
UnexpectedValueException | if the command response was malformed |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::drop | ( | array | $options = [] | ) |
Drop this collection.
array | $options | Additional options |
array|object | Command result document |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::dropIndex | ( | $indexName, | |
array | $options = [] ) |
Drop a single index in the collection.
string | IndexInfo | $indexName | Index name or model object |
array | $options | Additional options |
array|object | Command result document |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::dropIndexes | ( | array | $options = [] | ) |
Drop all indexes in the collection.
array | $options | Additional options |
array|object | Command result document |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::estimatedDocumentCount | ( | array | $options = [] | ) |
Gets an estimated number of documents in the collection using the collection metadata.
array | $options | Command options |
integer |
UnexpectedValueException | if the command response was malformed |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::explain | ( | Explainable | $explainable, |
array | $options = [] ) |
Explains explainable commands.
Explainable | $explainable | Command on which to run explain |
array | $options | Additional options |
array|object |
UnsupportedException | if explainable or options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::find | ( | $filter = [], | |
array | $options = [] ) |
Finds documents matching the query.
array | object | $filter | Query by which to filter documents |
array | $options | Additional options |
Cursor |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::findOne | ( | $filter = [], | |
array | $options = [] ) |
Finds a single document matching the query.
array | object | $filter | Query by which to filter documents |
array | $options | Additional options |
array|object|null |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::findOneAndDelete | ( | $filter, | |
array | $options = [] ) |
Finds a single document and deletes it, returning the original.
The document to return may be null if no document matched the filter.
array | object | $filter | Query by which to filter documents |
array | $options | Command options |
array|object|null |
UnexpectedValueException | if the command response was malformed |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::findOneAndReplace | ( | $filter, | |
$replacement, | |||
array | $options = [] ) |
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.
array | object | $filter | Query by which to filter documents |
array | object | $replacement | Replacement document |
array | $options | Command options |
array|object|null |
UnexpectedValueException | if the command response was malformed |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::findOneAndUpdate | ( | $filter, | |
$update, | |||
array | $options = [] ) |
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.
array | object | $filter | Query by which to filter documents |
array | object | $update | Update to apply to the matched document |
array | $options | Command options |
array|object|null |
UnexpectedValueException | if the command response was malformed |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::getCollectionName | ( | ) |
Return the collection name.
string |
MongoDB\Collection::getDatabaseName | ( | ) |
Return the database name.
string |
MongoDB\Collection::getManager | ( | ) |
Return the Manager.
Manager |
MongoDB\Collection::getNamespace | ( | ) |
Return the collection namespace.
string |
MongoDB\Collection::getReadConcern | ( | ) |
Return the read concern for this collection.
ReadConcern |
MongoDB\Collection::getReadPreference | ( | ) |
Return the read preference for this collection.
ReadPreference |
MongoDB\Collection::getTypeMap | ( | ) |
Return the type map for this collection.
array |
MongoDB\Collection::getWriteConcern | ( | ) |
Return the write concern for this collection.
WriteConcern |
MongoDB\Collection::insertMany | ( | array | $documents, |
array | $options = [] ) |
Inserts multiple documents.
array[] | object[] | $documents | The documents to insert |
array | $options | Command options |
InsertManyResult |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::insertOne | ( | $document, | |
array | $options = [] ) |
Inserts one document.
array | object | $document | The document to insert |
array | $options | Command options |
InsertOneResult |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::listIndexes | ( | array | $options = [] | ) |
Returns information for all indexes for the collection.
IndexInfoIterator |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::mapReduce | ( | JavascriptInterface | $map, |
JavascriptInterface | $reduce, | ||
$out, | |||
array | $options = [] ) |
Executes a map-reduce aggregation on the collection.
JavascriptInterface | $map | Map function |
JavascriptInterface | $reduce | Reduce function |
string | array | object | $out | Output specification |
array | $options | Command options |
MapReduceResult |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
UnexpectedValueException | if the command response was malformed |
MongoDB\Collection::rename | ( | string | $toCollectionName, |
?string | $toDatabaseName = null, | ||
array | $options = [] ) |
Renames the collection.
string | $toCollectionName | New name of the collection |
string | null | $toDatabaseName | New database name of the collection. Defaults to the original database. |
array | $options | Additional options |
array|object | Command result document |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::replaceOne | ( | $filter, | |
$replacement, | |||
array | $options = [] ) |
Replaces at most one document matching the filter.
array | object | $filter | Query by which to filter documents |
array | object | $replacement | Replacement document |
array | $options | Command options |
UpdateResult |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::updateMany | ( | $filter, | |
$update, | |||
array | $options = [] ) |
Updates all documents matching the filter.
array | object | $filter | Query by which to filter documents |
array | object | $update | Update to apply to the matched documents |
array | $options | Command options |
UpdateResult |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::updateOne | ( | $filter, | |
$update, | |||
array | $options = [] ) |
Updates at most one document matching the filter.
array | object | $filter | Query by which to filter documents |
array | object | $update | Update to apply to the matched document |
array | $options | Command options |
UpdateResult |
UnsupportedException | if options are not supported by the selected server |
InvalidArgumentException | for parameter/option parsing errors |
DriverRuntimeException | for other driver errors (e.g. connection errors) |
MongoDB\Collection::watch | ( | array | $pipeline = [], |
array | $options = [] ) |
Create a change stream for watching changes to the collection.
array | $pipeline | List of pipeline operations |
array | $options | Command options |
ChangeStream |
InvalidArgumentException | for parameter/option parsing errors |
MongoDB\Collection::withOptions | ( | array | $options = [] | ) |
Get a clone of this collection with different options.
array | $options | Collection constructor options |
Collection |
InvalidArgumentException | for parameter/option parsing errors |