How do you rename a MongoDB database?

前端 未结 10 1561
难免孤独
难免孤独 2020-11-29 15:04

There\'s a typo in my MongoDB database name and I\'m looking to rename the database.

I can copy and delete like so...

db.copyDatabase(\'old_name\', \         


        
10条回答
  •  被撕碎了的回忆
    2020-11-29 15:20

    The above process is slow,you can use below method but you need to move collection by collection to another db.

    use admin
    db.runCommand({renameCollection: "[db_old_name].[collection_name]", to: "[db_new_name].[collection_name]"})
    

提交回复
热议问题