Navigation
This version of the documentation is archived and no longer supported.

db.cloneDatabase()

On this page

Definition

db.cloneDatabase("hostname")

Copies a remote database to the current database. The command assumes that the remote database has the same name as the current database.

Parameter Type Description
hostname string The hostname of the database to copy.

This method provides a wrapper around the clone command.

Behavior

Data

The db.cloneDatabase() method does not snapshot the database. If any clients update the database you’re copying at any point during the clone operation, the resulting database may be inconsistent.

Locks

The destination database will be locked periodically during the clone operation. In other words, db.cloneDatabase() will occasionally yield to allow other operations on the database to complete.

FeatureCompatibilityVersion

You cannot copy data between a mongod instance with featureCompatibilityVersion (FCV) 3.6 and a MongoDB version 3.4 and earlier mongod instance.

For example:

Instance 1 Instance 2  
Version 3.6 mongod with FCV 3.6 Version 3.6 mongod with FCV 3.6 Can copy data.
Version 3.6 mongod with FCV 3.6 Version 3.6 mongod with FCV 3.4 Can copy data.
Version 3.6 mongod with FCV 3.6 Version 3.4 mongod with FCV 3.4 Cannot copy data. Instance 2 must be a MongoDB version 3.6
Version 3.6 mongod with FCV 3.4 Version 3.4 mongod with FCV 3.4 Can copy data.
Version 3.6 mongod with FCV 3.4 Version 3.2 mongod Can copy data.

Operations that copy data include:

Example

To clone a database named importdb on a host named hostname, issue the following:

use importdb
db.cloneDatabase("hostname")

New databases are implicitly created, so the current host does not need to have a database named importdb for this command to succeed.

See also

copydb