- Reference >
mongoShell Methods >- Database Methods >
- db.cloneDatabase()
db.cloneDatabase()¶
On this page
Definition¶
-
db.cloneDatabase("hostname")¶ Deprecated since version 4.0: MongoDB deprecates
cloneand its helperdb.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 hostnamestring The hostname of the database to copy. This method provides a wrapper around the
clonecommand.
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:
db.cloneCollection()and the commandcloneCollectiondb.cloneDatabase()and the commandclonedb.copyDatabase()and the commandcopydb