MongoDB\Client::__get()
定义
MongoDB\Client::__get()
在服务器上选择一个数据库。这是魔术方法的别名,对应于
selectDatabase()
方法。function __get(string $databaseName): MongoDB\Database
参数
$databaseName
: string- 要选择的数据库名称。
返回值
一个 MongoDB\Database
对象。
行为
所选数据库继承自 Client
对象的选项,如读取偏好和类型映射。如果您想覆盖任何选项,请使用 MongoDB\Client::selectDatabase()
方法。
注意
要选择名称包含特殊字符(如 -
)的数据库,请使用复杂语法,例如 $client->{'that-database'}
。
或者,MongoDB\Client::selectDatabase()
支持选择名称包含特殊字符的数据库。
示例
以下示例选择了 test
和 another-app
数据库
$client = new MongoDB\Client; $test = $client->test; $anotherApp = $client->{'another-app'};