MongoDB 如何修改数据库名称
怪我咯
怪我咯 2017-04-24 09:12:28
0
2
819

如题,在命令行里运行修改已有数据库名称

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
迷茫

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

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

==2017.4.4 Update==
is still an indirect solution, but WiredTigerthere is a more convenient solution for the storage engine: db.renameCollection.

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

When you move all collections to a new library, it is equivalent to renaming the entire library. This will be much faster than copyDatabase.

Note: renameCollection cannot be used for shard sets

阿神

db.help()

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template