Major - P3
(copied to CRM)
[UPDATE Sep 10, 2019]
The "copydb" command is deprecated, please use these two commands instead:
1. mongodump (to back up data)
2. mongorestore (to recover data from mongodump into a new namespace)
We are aware of how painful and long it is to rename a database in MongoDB. 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. In MMAPv1 files, the namespace (e.g.: dbName.collection) 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. This impacts:
- the .ns file
- every single numbered file for the collection
- the namespace for every index
- internal unique names of each collection and index
- contents of system.namespaces and system.indexes (or their equivalents in the future)
- other locations I may be missing
This is just to accomplish a rename of a single database in a standalone mongod instance. 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.
There would be absolutely no way to do this on a live system.
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.
MongoDB Product Team
Having the ability to rename databases would be nice. That would allow things like cloning a database with straight file copies plus a rename (to avoid having to wait on index builds when using db.copyDatabase).
- is related to
TOOLS-2387 Tools: Rename databases
DOCS-13024 Surface namespace rename example in assertion from copyDatabase deprecation link
- mentioned in