Example: MongoDB: db.collection.renameCollection() method The db.collection.renameCollection() method operates within a collection by changing the metadata associated with a given collection.
RenameCollection has different performance implications depending on the target namespace. To do it offline, it would require re-writing every single database file to accommodate the new name, and at that point it would be as slow as the current "copydb" command.Īlthough Mongodb does not provide the rename Database command, it provides the r ename Collection command, which not only modifies the collection name, but also modifies the database name. There would be absolutely no way to do this on a live system.
#Mongodb compass rename collection full
For replica sets the above would need to be done on every replica node, plus on each node every single oplog entry that refers this database would have to be somehow invalidated or rewritten, and then if it's a sharded cluster, one also needs to add these changes to every shard if the DB is sharded, plus the config servers have all the shard metadata in terms of namespaces with their full names. This is just to accomplish a rename of a single database in a standalone mongod instance.
contents of system.namespaces and system.indexes (or their equivalents in the future).internal unique names of each collection and index.every single numbered file for the collection.In MMAPv1 files, the namespace (e.g.: llection) that describes every single collection and index includes the database name, so to rename a set of database files, every single namespace string would have to be rewritten. Unfortunately, this is not an simple feature for us to implement due to the way that database metadata is stored in the original (default) storage engine.