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



The cloneCollection command copies a collection from a remote server to the server where you run the command. cloneCollection does not allow you to clone a collection through a mongos: you must connect directly to the mongod instance.

  • from – Specify a resolvable hostname, and optional port number of the remote server where the specified collection resides.
  • query – Optional. A query document, in the form of a document, that filters the documents in the remote collection that cloneCollection will copy to the current database. See db.collection.find().
  • copyIndexes (Boolean) – Optional. true by default. When set to false the indexes on the originating server are not copied with the documents in the collection.

Consider the following example:

{ cloneCollection: "users.profiles", from: "", query: { active: true }, copyIndexes: false }

This operation copies the profiles collection from the users database on the server at The operation only copies documents that satisfy the query { active: true } and does not copy indexes. cloneCollection copies indexes by default, but you can disable this behavior by setting { copyIndexes: false }. The query and copyIndexes arguments are optional.

cloneCollection creates a collection on the current database with the same name as the origin collection. If, in the above example, the profiles collection already exists in the local database, then MongoDB appends documents in the remote collection to the destination collection.