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


On this page



Copies a collection from a remote mongod instance to the current mongod instance. cloneCollection creates a collection in a database with the same name as the remote collection’s database. cloneCollection takes the following form:

{ cloneCollection: "<namespace>",
  from: "<hostname>",
  query: { <query> },
  writeConcern: { <write concern> },
  bypassDocumentValidation: <boolean>

cloneCollection has the following fields:

Field Type Description
cloneCollection string The namespace of the collection to copy. The namespace is a combination of the database name and the name of the collection.
from string The address of the server to clone from.
query document Optional. A query that filters the documents in the source collection that cloneCollection will copy to the current database.
writeConcern document Optional. A document that expresses the write concern for the operation. Omit to use the default write concern.
bypassDocumentValidation boolean

Optional. Enables cloneCollection to bypass document validation during the operation. This lets you insert documents that do not meet the validation requirements.

New in version 3.2.

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



mongos does not support cloneCollection.


cloneCollection cannot be used if the from server has authorization enabled.


Changed in version 3.0.

If the given namespace already exists in the destination mongod instance, cloneCollection will return an error.


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.getSiblingDB("users").runCommand( { cloneCollection: "users.profiles",
                 from: "",
                 query: { 'active' : true }
               } )

This operation copies the profiles collection from the users database on the server at into the users database on the local server. The operation only copies documents that satisfy the query { 'active' : true }.