Database
in package
Table of Contents
- $databaseName : string
- $defaultTypeMap : array<string|int, mixed>
- $manager : Manager
- $readConcern : ReadConcern
- $readPreference : ReadPreference
- $typeMap : array<string|int, mixed>
- $wireVersionForReadConcernWithWriteStage : int
- $writeConcern : WriteConcern
- __construct() : mixed
- Constructs new Database instance.
- __debugInfo() : array<string|int, mixed>
- Return internal properties for debugging purposes.
- __get() : Collection
- Select a collection within this database.
- __toString() : string
- Return the database name.
- aggregate() : Traversable
- 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
- command() : Cursor
- Execute a command on this database.
- createCollection() : array<string|int, mixed>|object
- Create a new collection explicitly.
- drop() : array<string|int, mixed>|object
- Drop this database.
- dropCollection() : array<string|int, mixed>|object
- Drop a collection within this database.
- getDatabaseName() : string
- Returns the database name.
- getManager() : Manager
- Return the Manager.
- getReadConcern() : ReadConcern
- Return the read concern for this database.
- getReadPreference() : ReadPreference
- Return the read preference for this database.
- getTypeMap() : array<string|int, mixed>
- Return the type map for this database.
- getWriteConcern() : WriteConcern
- Return the write concern for this database.
- listCollectionNames() : Iterator
- Returns the names of all collections in this database
- listCollections() : CollectionInfoIterator
- Returns information for all collections in this database.
- modifyCollection() : array<string|int, mixed>|object
- Modifies a collection or view.
- renameCollection() : array<string|int, mixed>|object
- Rename a collection within this database.
- selectCollection() : Collection
- Select a collection within this database.
- selectGridFSBucket() : Bucket
- Select a GridFS bucket within this database.
- watch() : ChangeStream
- Create a change stream for watching changes to the database.
- withOptions() : Database
- Get a clone of this database with different options.
Properties
$databaseName
private
string
$databaseName
$defaultTypeMap
private
static array<string|int, mixed>
$defaultTypeMap
= ['array' => \MongoDB\Model\BSONArray::class, 'document' => \MongoDB\Model\BSONDocument::class, 'root' => \MongoDB\Model\BSONDocument::class]
$manager
private
Manager
$manager
$readConcern
private
ReadConcern
$readConcern
$readPreference
private
ReadPreference
$readPreference
$typeMap
private
array<string|int, mixed>
$typeMap
$wireVersionForReadConcernWithWriteStage
private
static int
$wireVersionForReadConcernWithWriteStage
= 8
$writeConcern
private
WriteConcern
$writeConcern
Methods
__construct()
Constructs new Database instance.
public
__construct(Manager $manager, string $databaseName[, array<string|int, mixed> $options = [] ]) : mixed
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 : Manager
-
Manager instance from the driver
- $databaseName : string
-
Database name
- $options : array<string|int, mixed> = []
-
Database options
Tags
Return values
mixed —__debugInfo()
Return internal properties for debugging purposes.
public
__debugInfo() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —__get()
Select a collection within this database.
public
__get(string $collectionName) : Collection
Note: collections whose names contain special characters (e.g. ".") may be selected with complex syntax (e.g. $database->{"system.profile"}) or .
Parameters
- $collectionName : string
-
Name of the collection to select
Tags
Return values
Collection —__toString()
Return the database name.
public
__toString() : string
Return values
string —aggregate()
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
public
aggregate(array<string|int, mixed> $pipeline[, array<string|int, mixed> $options = [] ]) : Traversable
Parameters
- $pipeline : array<string|int, mixed>
-
List of pipeline operations
- $options : array<string|int, mixed> = []
-
Command options
Tags
Return values
Traversable —command()
Execute a command on this database.
public
command(array<string|int, mixed>|object $command[, array<string|int, mixed> $options = [] ]) : Cursor
Parameters
- $command : array<string|int, mixed>|object
-
Command document
- $options : array<string|int, mixed> = []
-
Options for command execution
Tags
Return values
Cursor —createCollection()
Create a new collection explicitly.
public
createCollection(string $collectionName[, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>|object
Parameters
- $collectionName : string
- $options : array<string|int, mixed> = []
Tags
Return values
array<string|int, mixed>|object —Command result document
drop()
Drop this database.
public
drop([array<string|int, mixed> $options = [] ]) : array<string|int, mixed>|object
Parameters
- $options : array<string|int, mixed> = []
-
Additional options
Tags
Return values
array<string|int, mixed>|object —Command result document
dropCollection()
Drop a collection within this database.
public
dropCollection(string $collectionName[, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>|object
Parameters
- $collectionName : string
-
Collection name
- $options : array<string|int, mixed> = []
-
Additional options
Tags
Return values
array<string|int, mixed>|object —Command result document
getDatabaseName()
Returns the database name.
public
getDatabaseName() : string
Return values
string —getManager()
Return the Manager.
public
getManager() : Manager
Return values
Manager —getReadConcern()
Return the read concern for this database.
public
getReadConcern() : ReadConcern
Tags
Return values
ReadConcern —getReadPreference()
Return the read preference for this database.
public
getReadPreference() : ReadPreference
Return values
ReadPreference —getTypeMap()
Return the type map for this database.
public
getTypeMap() : array<string|int, mixed>
Return values
array<string|int, mixed> —getWriteConcern()
Return the write concern for this database.
public
getWriteConcern() : WriteConcern
Tags
Return values
WriteConcern —listCollectionNames()
Returns the names of all collections in this database
public
listCollectionNames([array<string|int, mixed> $options = [] ]) : Iterator
Parameters
- $options : array<string|int, mixed> = []
Tags
Return values
Iterator —listCollections()
Returns information for all collections in this database.
public
listCollections([array<string|int, mixed> $options = [] ]) : CollectionInfoIterator
Parameters
- $options : array<string|int, mixed> = []
Tags
Return values
CollectionInfoIterator —modifyCollection()
Modifies a collection or view.
public
modifyCollection(string $collectionName, array<string|int, mixed> $collectionOptions[, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>|object
Parameters
- $collectionName : string
-
Collection or view to modify
- $collectionOptions : array<string|int, mixed>
-
Collection or view options to assign
- $options : array<string|int, mixed> = []
-
Command options
Tags
Return values
array<string|int, mixed>|object —renameCollection()
Rename a collection within this database.
public
renameCollection(string $fromCollectionName, string $toCollectionName[, string|null $toDatabaseName = null ][, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>|object
Parameters
- $fromCollectionName : string
-
Collection name
- $toCollectionName : string
-
New name of the collection
- $toDatabaseName : string|null = null
-
New database name of the collection. Defaults to the original database.
- $options : array<string|int, mixed> = []
-
Additional options
Tags
Return values
array<string|int, mixed>|object —Command result document
selectCollection()
Select a collection within this database.
public
selectCollection(string $collectionName[, array<string|int, mixed> $options = [] ]) : Collection
Parameters
- $collectionName : string
-
Name of the collection to select
- $options : array<string|int, mixed> = []
-
Collection constructor options
Tags
Return values
Collection —selectGridFSBucket()
Select a GridFS bucket within this database.
public
selectGridFSBucket([array<string|int, mixed> $options = [] ]) : Bucket
Parameters
- $options : array<string|int, mixed> = []
-
Bucket constructor options
Tags
Return values
Bucket —watch()
Create a change stream for watching changes to the database.
public
watch([array<string|int, mixed> $pipeline = [] ][, array<string|int, mixed> $options = [] ]) : ChangeStream
Parameters
- $pipeline : array<string|int, mixed> = []
-
List of pipeline operations
- $options : array<string|int, mixed> = []
-
Command options
Tags
Return values
ChangeStream —withOptions()
Get a clone of this database with different options.
public
withOptions([array<string|int, mixed> $options = [] ]) : Database
Parameters
- $options : array<string|int, mixed> = []
-
Database constructor options