how can i update Database name and collection name ?
In the mongo shell, this helper could be useful
There is no method to rename database, as far as I searched, but this could be useful
db.copyDatabase('old_name', 'new_name'); use old_name db.dropDatabase();
Where you copy the database, and drop the old one.
Hello @Santiago_Miranda , thank you for your help!!!
but I also want know that why it not allow rename database directly instead of creating new one and drop old one.
Thank you in advance !!!
To be honest, that answer is over the top of my head, it’s related to how MongoDB stores databases’ metadata.
You can read this stackoverflow post though.
Also, apparently copying a database like that is very slow, so you should:
mongodumpthe old database
mongorestorewith new name
dropDatabasethe old database
You’ll find how to in the same url I linked before.
For a more formal description, see the ticket in JIRA.
Thanks for sharing these resources.
@mansi_joshi Please note that starting in MongoDB 4.2, we have removed the support for
db.copyDatabase() command and you should use
mongorestore to copy/clone a database as mentioned by @Santiago_Miranda.
Let us know if you have any other doubts.