MongoDB\数据库::withOptions()
定义
参数
$options
: array指定所需选项的数组。
名称类型说明readConcern用于数据库操作的默认读关注。 Defaults to the original database's read concern.readPreference用于数据库操作的默认读取偏好(read preference)。默认为原始数据库的读取偏好(read preference)。typeMap阵列类型映射 应用于游标,决定如何将 BSON 文档转换为 PHP 值。默认为原始数据库的类型映射。writeConcern用于数据库操作的默认写关注(write concern)。Defaults to the original database's write concern.
返回值
一个MongoDB\Database
对象。
错误/异常
MongoDB\Exception\InvalidArgumentException
用于与参数或选项解析相关的错误。
例子
以下示例使用新的读取偏好(read preference)克隆现有的数据库对象:
$db = (new MongoDB\Client)->test; $newDb = $db->withOptions([ 'readPreference' => new MongoDB\Driver\ReadPreference('primaryPreferred'), ]);