How to update the name of a Database in MongoDB?
How to update the name of a Database in MongoDB?
I completed my post-graduation in 2013 in the engineering field. Engineering is the application of science and math to solve problems. Engineers figure out how things work and find practical uses for scientific discoveries. Scientists and inventors often get the credit for innovations that advance the human condition, but it is engineers who are instrumental in making those innovations available to the world. I love pet animals such as dogs, cats, etc.
Aryan Kumar
26-Aug-2023You can update the name of a database in MongoDB using the
renameDatabase()method. The syntax for therenameDatabase()method is as follows:Where
oldNameis the name of the database that you want to rename andnewNameis the new name of the database.For example, the following code would rename the database
mydbtonewdb:It is important to note that the
renameDatabase()method does not move the data in the database. It simply changes the name of the database.If you want to move the data in the database, you can use the
copyDatabase()method. The syntax for thecopyDatabase()method is as follows:Where
oldNameis the name of the database that you want to copy andnewNameis the new name of the database.For example, the following code would copy the database
mydbtonewdb:The
copyDatabase()method will create a new database callednewdband copy all of the data from the databasemydbto the new database.