db.collection.renameCollection() method operates within a
collection by changing the metadata associated with a given collection.
Refer to the documentation
renameCollection for additional
warnings and messages.
The method has the following limitations:
Changed in version 4.2.
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. Prior to MongoDB
4.2, renaming a collection within the same database with
renameCollection required obtaining an exclusive database
db.collection.renameCollection() method on a
collection object. For example:
This operation will rename the
rrecord collection to
the target name (i.e.
record) is the name of an existing collection,
then the operation will fail.