Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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

(no description)

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

Defines 1 class


Class: Database  - X-Ref

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

This class provides methods for database-specific operations and serves
as a gateway for accessing collections.

Supported options:

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

* readPreference (MongoDB\Driver\ReadPreference): The default read
preference to use for database operations and selected collections.
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 database operations and selected collections. Defaults to
the Manager's write concern.

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

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

return: array

__get(string $collectionName)   X-Ref
Select a collection within this database.

Note: collections whose names contain special characters (e.g. ".") may
be selected with complex syntax (e.g. $database->{"system.profile"}) or
{@link selectCollection()}.

param: string $collectionName Name of the collection to select
return: Collection

__toString()   X-Ref
Return the database name.

return: string

aggregate(array $pipeline, array $options = [])   X-Ref
Runs an aggregation framework pipeline on the database for pipeline
stages that do not require an underlying collection, such as $currentOp
and $listLocalSessions. Requires MongoDB >= 3.6

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

command($command, array $options = [])   X-Ref
Execute a command on this database.

param: array|object $command Command document
param: array        $options Options for command execution
return: Cursor

createCollection(string $collectionName, array $options = [])   X-Ref
Create a new collection explicitly.

return: array|object Command result document

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

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

dropCollection(string $collectionName, array $options = [])   X-Ref
Drop a collection within this database.

param: string $collectionName Collection name
param: array  $options        Additional options
return: array|object Command result document

getDatabaseName()   X-Ref
Returns the database name.

return: string

getManager()   X-Ref
Return the Manager.

return: Manager

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

return: ReadConcern

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

return: ReadPreference

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

return: array

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

return: WriteConcern

listCollectionNames(array $options = [])   X-Ref
Returns the names of all collections in this database


listCollections(array $options = [])   X-Ref
Returns information for all collections in this database.

return: CollectionInfoIterator

modifyCollection(string $collectionName, array $collectionOptions, array $options = [])   X-Ref
Modifies a collection or view.

param: string $collectionName    Collection or view to modify
param: array  $collectionOptions Collection or view options to assign
param: array  $options           Command options
return: array|object

renameCollection(string $fromCollectionName, string $toCollectionName, ?string $toDatabaseName = null, array $options = [])   X-Ref
Rename a collection within this database.

param: string      $fromCollectionName Collection name
param: string      $toCollectionName   New name of the collection
param: string|null $toDatabaseName     New database name of the collection. Defaults to the original database.
param: array       $options            Additional options
return: array|object Command result document

selectCollection(string $collectionName, array $options = [])   X-Ref
Select a collection within this database.

param: string $collectionName Name of the collection to select
param: array  $options        Collection constructor options
return: Collection

selectGridFSBucket(array $options = [])   X-Ref
Select a GridFS bucket within this database.

param: array $options Bucket constructor options
return: Bucket

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

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

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

param: array $options Database constructor options
return: Database