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: 546 lines (19 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Database:: (21 methods):
  __construct()
  __debugInfo()
  __get()
  __toString()
  aggregate()
  command()
  createCollection()
  drop()
  dropCollection()
  getDatabaseName()
  getManager()
  getReadConcern()
  getReadPreference()
  getTypeMap()
  getWriteConcern()
  listCollections()
  modifyCollection()
  selectCollection()
  selectGridFSBucket()
  watch()
  withOptions()


Class: Database  - X-Ref

__construct(Manager $manager, $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($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($collectionName, array $options = [])   X-Ref
Create a new collection explicitly.

param: string $collectionName
param: array  $options
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($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

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

param: array $options
return: CollectionInfoIterator

modifyCollection($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

selectCollection($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