Navigation

db.cloneDatabase()

On this page

Definition

db.cloneDatabase("hostname")

Deprecated since version 4.0: MongoDB deprecates clone and its helper db.cloneDatabase(). For information on alternatives, see copydb and clone Commands.

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 MongoDB 4.0 mongod instance with featureCompatibilityVersion (FCV) 4.0 and a MongoDB version 3.6 mongod instance.

Note

You cannot copy data between a MongoDB 4.0 mongod instance (regardless of the FCV value) and a MongoDB 3.4 and earlier mongod instance.

For example:

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

In general, if the mongod instance has its featureCompatibilityVersion (FCV) set to its MongoDB version, you cannot copy data between that instance and a mongod instance of an earlier MongoDB version.

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