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


db.cloneCollection(from, collection, query)

db.cloneCollection() provides a wrapper around cloneCollection for copying data directly between MongoDB instances. db.cloneCollection() does not allow you to clone a collection through a mongos: you must connect directly to the mongod instance.

  • from (string) – A host name, of the MongoDB instance that holds the collection you wish to copy
  • collection (string) – A collection in the MongoDB instance that you want to copy. db.cloneCollection() will only copy the collection with this name from database of the same name as the current database the remote MongoDB instance. If you want to copy a collection from a different database name you must use the cloneCollection directly.
  • query (document) – Optional. A standard MongoDB query document to limit the documents copied as part of the db.cloneCollection() operation.