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

db.コレクション.renameCollection()(mongoshメソッド)

MongoDB とドライバー

This page documents a mongosh method. To see the equivalent method in a MongoDB driver, see the corresponding page for your programming language:
db.collection.renameCollection(target, dropTarget)

コレクションの名前を変更します。renameCollectionデータベースコマンドのラッパーを提供します。

Parameter
タイプ
説明

target

string

コレクションの新しい名前。文字列を引用符で囲みます。詳細は、「命名制限」を参照してください。

dropTarget

ブール値

任意。trueの場合、 mongodではコレクションの名前を変更する前にrenameCollectiontargetが削除されます。デフォルト値はfalseです。

The db.collection.renameCollection() method operates within a collection by changing the metadata associated with a given collection.

追加の警告とメッセージについては、ドキュメント「renameCollection」を参照してください。

警告

The db.collection.renameCollection() method and renameCollection command will invalidate open cursors which interrupts queries that are currently returning data.

For MongoDB Change Streams, the db.collection.renameCollection() method and renameCollection command create an invalidate Event for any existing MongoDB Change Streams opened on the source or target collection.

バージョン5.0で変更。

シャーディングされたクラスター内のシャーディングされたコレクションまたはシャーディングされていないコレクションの名前を変更すると、ソース コレクションとターゲット コレクションだけがすべてのシャードでロックされます。ソース コレクションとターゲット コレクションでのその後の操作は、名前変更操作が完了するまで待つ必要があります。

MongoDB でのロックの詳細については、「FAQ: 同時実行性」を参照してください。

renameCollection() obtains an exclusive lock on the source and target collections for the duration of the operation. All subsequent operations on the collections must wait until renameCollection() completes.

A mongodump started with --oplog fails if a client issues db.collection.renameCollection() during the dump process. See mongodump.--oplog for more information.

Call the db.collection.renameCollection() method on a collection object. For example:

db.rrecord.renameCollection("record")

この操作により、 rrecordコレクションの名前がrecordに変更されます。ターゲット名(つまり、record )が既存のコレクションの名前である場合、操作は失敗します。

このページを評価

項目一覧