MongoDB\Collection::withOptions()
定义
参数
返回值
一个 MongoDB\Collection
对象。
错误/异常
MongoDB\Exception\InvalidArgumentException
用于与参数或选项解析相关的错误。
示例
以下示例使用新的读取偏好克隆现有的 Collection 对象
$collection = (new MongoDB\Client)->selectCollection('test', 'restaurants'); $newCollection = $sourceCollection->withOptions([ 'readPreference' => new MongoDB\Driver\ReadPreference('primaryPreferred'), ]);