Docs 菜单
Docs 主页
/ / /
PHP 库手册
/ /

MongoDB\Database::withOptions()

在此页面上

  • 定义
  • 参数
  • Return Values
  • 错误/异常
  • 例子
  • 另请参阅
MongoDB\Database::withOptions()

返回数据库对象的克隆,但具有不同的选项。

function withOptions(array $options = []): MongoDB\Database
$options : array

指定所需选项的数组。

名称
类型
说明

builderEncoder

MongoDB\Codec\Encoder

用于在查询和聚合选项中原生PHP类型序列化为BSON数据的编码器。如果省略,Database实例将使用默认编码器。

1.21版本新增

事务外的

MongoDB\Driver\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)克隆现有的数据库对象:

<?php
$db = (new MongoDB\Client)->test;
$newDb = $db->withOptions([
'readPreference' => new MongoDB\Driver\ReadPreference('primaryPreferred'),
]);

后退

watch()