Navigation

clone

On this page

clone

The clone command clones a database from a mongod instance to the current mongod instance.

The command takes the following form:

{ clone: <copyfromhost:port> }

To use the clone command, run the command on the destination server, specifying the source to copy from. The database where you run the command determines which database to copy from the source.

The mongo shell provides the method db.cloneDatabase() as a wrapper for the clone command.

Behavior

Data

The clone command 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, clone 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:

Replica Sets

The clone command can copy from a secondary member of a replica set.

Example

The following operation copies the marketing database from "db1.example.net:27017" to the mongod instance where you issue the db.runCommand().

use marketing
db.runCommand( { clone: "db1.example.net:27017" })
←   clean cloneCollection  →