How does MongoDB modify the database name

  mongodb, question

For example, run on the command line to modify the existing database name.

There is no direct method, only through copy then delete:

db.copyDatabase('old_name', 'new_name');
 use old_name

==2017.4.4 update = =
It is still an indirect plan, butWiredTigerThe storage engine already has a more convenient solution:db.renameCollection.

use admin;
 db.runCommand({renameCollection: "test.test", to: "test1.test"});

When you move all the collections to the new library, it is equivalent to renaming the entire library. This will be better thancopyDatabaseMuch faster.

Note: renameCollection cannot be used for shard sets.