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