Docs Menu
Docs Home
/ /

MongoDB\Client::__get()

MongoDB\Client::__get()

Selects a database on the server. This magic method is an alias for the selectDatabase() .

function __get(string $databaseName): MongoDB\Database
$databaseName : string
The name of the database to select.

A MongoDB\Database object.

La base de datos seleccionada hereda opciones como la preferencia de lectura y la asignación de tipos del objeto. Si desea Client MongoDB\Client::selectDatabase() anular alguna opción, utilice el método.

Nota

To select databases whose names contain special characters, such as -, use complex syntax, as in $client->{'that-database'}.

Alternatively, MongoDB\Client::selectDatabase() supports selecting databases whose names contain special characters.

The following example selects the test and another-app databases:

<?php
$client = new MongoDB\Client;
$test = $client->test;
$anotherApp = $client->{'another-app'};

Volver

__construct()

En esta página