バージョン1.10の新機能。
定義
パラメーター
$fromCollectionName: string- 名前を変更するコレクションの名前。
$toCollectionName: string- コレクションの新しい名前。
$toDatabaseName: string- コレクションの新しいデータベース名。 新しいデータベース名を指定しない場合は、現在のデータベースが使用されます。 新しい名前で別のデータベースが指定されている場合、コマンドはコレクションを新しいデータベースにコピーし、ソース コレクションを削除します。
$options: 配列必要なオプションを指定する配列。
名前タイプ説明comment
混合
データベースプロファイラ、 currentOp出力、およびログから操作を追跡するのに役立つ任意のコメントを指定できるようにします。
このオプションは MongoDB 4.4 以降で使用可能であり、古いサーバー バージョンで指定すると実行時に例外が発生します。
バージョン1.13の新機能。
dropTarget
ブール値
trueの場合、MongoDB はコレクションの名前を変更する前にターゲットを削除します。 デフォルト値はfalseです。セッション
操作に関連付けるクライアント セッション。
typeMap
配列
The type map to apply to cursors, which determines how BSON documents are converted to PHP values. Defaults to the database's type map.
これは返されたコマンドの結果ドキュメントに使用されます。
writeConcern
操作に使用する書込み保証 ( write concern )。 データベースの書込み保証 (write concern) のデフォルト。
Return Values
An array or object with the result document of the renameCollection command. The return type will depend on the typeMap option.
エラーと例外
MongoDB\Exception\UnsupportedExceptionオプションが使用され、選択したサーバーでサポートされていない場合(例: collation 、 readConcern 、 writeConcern )。
MongoDB\Exception\InvalidArgumentException は、パラメータまたはオプションの解析に関連するエラーの場合は です。
MongoDB$Driver\Exception\RuntimeException は、拡張レベルの他のエラーの場合(例:)。
例
次の例では、 testデータベース内のrestaurantsコレクションの名前をplacesに変更します。
$db = (new MongoDB\Client)->test; $result = $db->renameCollection('restaurants', 'places'); var_dump($result);
出力は次のようになります。
object(MongoDB\Model\BSONDocument)#8 (1) { ["storage":"ArrayObject":private]=> array(1) { ["ok"]=> float(1) } }
その他の参照
MongoDB マニュアルのrenameCollectionコマンド参照