Copying Databases

Another common task with databases is copying them. Copying a database creates a duplicate of the database that is exactly the same except for the name. There are several reasons you might want to copy a database—for example, to have a backup while you perform heavy changes or as an archive.

To create a copy of a database, you switch to that database and then use copyDatabase(origin, destination, [hostname]) to create a copy. The origin parameter is a string that specifies the name of the database to copy. The destination parameter specifies the name of the database to create on this MongoDB server. The optional hostname parameter specifies a hostname of the origin database MongoDB server if you are copying a database from a ...

Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.