Moodle PHP Documentation 4.1
Moodle 4.1.11 (Build: 20240610) (c8c84b4af18)
MongoDB\Database Class Reference

Public Member Functions

 __construct (Manager $manager, string $databaseName, array $options=[])
 Constructs new Database instance.
 
 __debugInfo ()
 Return internal properties for debugging purposes.
 
 __get (string $collectionName)
 Select a collection within this database.
 
 __toString ()
 Return the database name.
 
 aggregate (array $pipeline, array $options=[])
 Runs an aggregation framework pipeline on the database for pipeline stages that do not require an underlying collection, such as $currentOp and $listLocalSessions.
 
 command ($command, array $options=[])
 Execute a command on this database.
 
 createCollection (string $collectionName, array $options=[])
 Create a new collection explicitly.
 
 drop (array $options=[])
 Drop this database.
 
 dropCollection (string $collectionName, array $options=[])
 Drop a collection within this database.
 
 getDatabaseName ()
 Returns the database name.
 
 getManager ()
 Return the Manager.
 
 getReadConcern ()
 Return the read concern for this database.
 
 getReadPreference ()
 Return the read preference for this database.
 
 getTypeMap ()
 Return the type map for this database.
 
 getWriteConcern ()
 Return the write concern for this database.
 
 listCollectionNames (array $options=[])
 Returns the names of all collections in this database.
 
 listCollections (array $options=[])
 Returns information for all collections in this database.
 
 modifyCollection (string $collectionName, array $collectionOptions, array $options=[])
 Modifies a collection or view.
 
 renameCollection (string $fromCollectionName, string $toCollectionName, ?string $toDatabaseName=null, array $options=[])
 Rename a collection within this database.
 
 selectCollection (string $collectionName, array $options=[])
 Select a collection within this database.
 
 selectGridFSBucket (array $options=[])
 Select a GridFS bucket within this database.
 
 watch (array $pipeline=[], array $options=[])
 Create a change stream for watching changes to the database.
 
 withOptions (array $options=[])
 Get a clone of this database with different options.
 

Constructor & Destructor Documentation

◆ __construct()

MongoDB\Database::__construct ( Manager $manager,
string $databaseName,
array $options = [] )

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.
Parameters
Manager$managerManager instance from the driver
string$databaseNameDatabase name
array$optionsDatabase options
Exceptions
InvalidArgumentExceptionfor parameter/option parsing errors

Member Function Documentation

◆ __debugInfo()

MongoDB\Database::__debugInfo ( )

Return internal properties for debugging purposes.

See also
https://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.debuginfo
Return values
array

◆ __get()

MongoDB\Database::__get ( string $collectionName)

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 selectCollection().

See also
https://php.net/oop5.overloading#object.get
https://php.net/types.string#language.types.string.parsing.complex
Parameters
string$collectionNameName of the collection to select
Return values
Collection

◆ __toString()

MongoDB\Database::__toString ( )

Return the database name.

Return values
string

◆ aggregate()

MongoDB\Database::aggregate ( array $pipeline,
array $options = [] )

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

See also
Aggregate\__construct() for supported options
Parameters
array$pipelineList of pipeline operations
array$optionsCommand options
Return values
Traversable
Exceptions
UnexpectedValueExceptionif the command response was malformed
UnsupportedExceptionif options are not supported by the selected server
InvalidArgumentExceptionfor parameter/option parsing errors
DriverRuntimeExceptionfor other driver errors (e.g. connection errors)

◆ command()

MongoDB\Database::command ( $command,
array $options = [] )

Execute a command on this database.

See also
DatabaseCommand\__construct() for supported options
Parameters
array | object$commandCommand document
array$optionsOptions for command execution
Return values
Cursor
Exceptions
InvalidArgumentExceptionfor parameter/option parsing errors
DriverRuntimeExceptionfor other driver errors (e.g. connection errors)

◆ createCollection()

MongoDB\Database::createCollection ( string $collectionName,
array $options = [] )

Create a new collection explicitly.

See also
CreateCollection\__construct() for supported options
Return values
array|objectCommand result document
Exceptions
UnsupportedExceptionif options are not supported by the selected server
InvalidArgumentExceptionfor parameter/option parsing errors
DriverRuntimeExceptionfor other driver errors (e.g. connection errors)

◆ drop()

MongoDB\Database::drop ( array $options = [])

Drop this database.

See also
DropDatabase\__construct() for supported options
Parameters
array$optionsAdditional options
Return values
array|objectCommand result document
Exceptions
UnsupportedExceptionif options are unsupported on the selected server
InvalidArgumentExceptionfor parameter/option parsing errors
DriverRuntimeExceptionfor other driver errors (e.g. connection errors)

◆ dropCollection()

MongoDB\Database::dropCollection ( string $collectionName,
array $options = [] )

Drop a collection within this database.

See also
DropCollection\__construct() for supported options
Parameters
string$collectionNameCollection name
array$optionsAdditional options
Return values
array|objectCommand result document
Exceptions
UnsupportedExceptionif options are unsupported on the selected server
InvalidArgumentExceptionfor parameter/option parsing errors
DriverRuntimeExceptionfor other driver errors (e.g. connection errors)

◆ getDatabaseName()

MongoDB\Database::getDatabaseName ( )

Returns the database name.

Return values
string

◆ getManager()

MongoDB\Database::getManager ( )

Return the Manager.

Return values
Manager

◆ getReadConcern()

MongoDB\Database::getReadConcern ( )

Return the read concern for this database.

See also
https://php.net/manual/en/mongodb-driver-readconcern.isdefault.php
Return values
ReadConcern

◆ getReadPreference()

MongoDB\Database::getReadPreference ( )

Return the read preference for this database.

Return values
ReadPreference

◆ getTypeMap()

MongoDB\Database::getTypeMap ( )

Return the type map for this database.

Return values
array

◆ getWriteConcern()

MongoDB\Database::getWriteConcern ( )

Return the write concern for this database.

See also
https://php.net/manual/en/mongodb-driver-writeconcern.isdefault.php
Return values
WriteConcern

◆ listCollectionNames()

MongoDB\Database::listCollectionNames ( array $options = [])

Returns the names of all collections in this database.

See also
ListCollectionNames\__construct() for supported options
Exceptions
InvalidArgumentExceptionfor parameter/option parsing errors
DriverRuntimeExceptionfor other driver errors (e.g. connection errors)

◆ listCollections()

MongoDB\Database::listCollections ( array $options = [])

Returns information for all collections in this database.

See also
ListCollections\__construct() for supported options
Return values
CollectionInfoIterator
Exceptions
InvalidArgumentExceptionfor parameter/option parsing errors
DriverRuntimeExceptionfor other driver errors (e.g. connection errors)

◆ modifyCollection()

MongoDB\Database::modifyCollection ( string $collectionName,
array $collectionOptions,
array $options = [] )

Modifies a collection or view.

See also
ModifyCollection\__construct() for supported options
Parameters
string$collectionNameCollection or view to modify
array$collectionOptionsCollection or view options to assign
array$optionsCommand options
Return values
array|object
Exceptions
InvalidArgumentExceptionfor parameter/option parsing errors
DriverRuntimeExceptionfor other driver errors (e.g. connection errors)

◆ renameCollection()

MongoDB\Database::renameCollection ( string $fromCollectionName,
string $toCollectionName,
?string $toDatabaseName = null,
array $options = [] )

Rename a collection within this database.

See also
RenameCollection\__construct() for supported options
Parameters
string$fromCollectionNameCollection name
string$toCollectionNameNew name of the collection
string | null$toDatabaseNameNew database name of the collection. Defaults to the original database.
array$optionsAdditional options
Return values
array|objectCommand result document
Exceptions
UnsupportedExceptionif options are unsupported on the selected server
InvalidArgumentExceptionfor parameter/option parsing errors
DriverRuntimeExceptionfor other driver errors (e.g. connection errors)

◆ selectCollection()

MongoDB\Database::selectCollection ( string $collectionName,
array $options = [] )

Select a collection within this database.

See also
Collection\__construct() for supported options
Parameters
string$collectionNameName of the collection to select
array$optionsCollection constructor options
Return values
Collection
Exceptions
InvalidArgumentExceptionfor parameter/option parsing errors

◆ selectGridFSBucket()

MongoDB\Database::selectGridFSBucket ( array $options = [])

Select a GridFS bucket within this database.

See also
Bucket\__construct() for supported options
Parameters
array$optionsBucket constructor options
Return values
Bucket
Exceptions
InvalidArgumentExceptionfor parameter/option parsing errors

◆ watch()

MongoDB\Database::watch ( array $pipeline = [],
array $options = [] )

Create a change stream for watching changes to the database.

See also
Watch\__construct() for supported options
Parameters
array$pipelineList of pipeline operations
array$optionsCommand options
Return values
ChangeStream
Exceptions
InvalidArgumentExceptionfor parameter/option parsing errors

◆ withOptions()

MongoDB\Database::withOptions ( array $options = [])

Get a clone of this database with different options.

See also
Database\__construct() for supported options
Parameters
array$optionsDatabase constructor options
Return values
Database
Exceptions
InvalidArgumentExceptionfor parameter/option parsing errors

The documentation for this class was generated from the following file: