- Reference >
mongo
Shell Methods >- Database Methods >
- db.cloneCollection()
db.cloneCollection()¶
On this page
Definition¶
-
db.
cloneCollection
(from, collection, query)¶ Copies data directly between MongoDB instances. The
db.cloneCollection()
wraps thecloneCollection
database command and accepts the following arguments:Parameter Type Description from
string Host name of the MongoDB instance that holds the collection to copy. collection
string The 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 thecloneCollection
directly.query
document Optional. A standard query document that limits the documents copied as part of the db.cloneCollection()
operation. All query selectors available to thefind()
are available here.db.cloneCollection()
does not allow you to clone a collection through amongos
. You must connect directly to themongod
instance.