定義
パラメーター
$options: 配列必要なオプションを指定する配列。
名前タイプ説明builderEncoder
MongoDB\Codec\Encoderクエリおよび集計オプションでネイティブPHP型をBSONデータに直列化するために使用されるエンコード。省略した場合、
Databaseインスタンスはデフォルトのエンコードを使用します。バージョン1.21の新機能。
ReadConcern
データベース操作に使用するデフォルトの読み取り保証 (read concern) です。 デフォルトは、元のデータベースの読み取り保証 (read concern) です。
readPreference
データベース操作に使用するデフォルトの読み込み設定 (read preference) 。 デフォルトでは、元のデータベースの読み込み設定(read preference)に設定されます。
typeMap
配列
The type map to apply to cursors, which determines how BSON documents are converted to PHP values. Defaults to the original database's type map.
writeConcern
データベース操作に使用するデフォルトの書込み保証 (write concern) です。 デフォルトは、元のデータベースの書込み保証 (write concern) です。
Return Values
MongoDB\Databaseオブジェクト。
エラーと例外
MongoDB\Exception\InvalidArgumentException は、パラメータまたはオプションの解析に関連するエラーの場合は です。
例
次の例では、既存の データベース オブジェクトを新しい読み込み設定(read preference)で複製します。
$db = (new MongoDB\Client)->test; $newDb = $db->withOptions([ 'readPreference' => new MongoDB\Driver\ReadPreference('primaryPreferred'), ]);