- Reference >
mongoShell Methods >- Database Methods >
- db.cloneDatabase()
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 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 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:
db.cloneCollection()and the commandcloneCollectiondb.cloneDatabase()and the commandclonedb.copyDatabase()and the commandcopydb