AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

MongoDB\Collection::withOptions()

MongoDB\Collection::withOptions()

Collection オブジェクトのクローンを返しますが、オプションは異なります。

function withOptions(array $options = []): MongoDB\Collection
$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

配列

The type map to apply to cursors, which determines how BSON documents are converted to PHP values. Defaults to the original collection's type map.

writeConcern

コレクション操作に使用するデフォルトの書込み保証 (write concern) です。 デフォルトは、元のコレクションの書込み保証 (write concern) の です。

MongoDB\Collectionオブジェクト。

MongoDB\Exception\InvalidArgumentException は、パラメータまたはオプションの解析に関連するエラーの場合は です。

次の例では、既存の コレクション オブジェクトを新しい読み込み設定(read preference)で複製します。

<?php
$collection = (new MongoDB\Client)->selectCollection('test', 'restaurants');
$newCollection = $sourceCollection->withOptions([
'readPreference' => new MongoDB\Driver\ReadPreference('primaryPreferred'),
]);