- Reference >
- Database Commands >
- Administration Commands >
- cloneCollection
cloneCollection¶
On this page
Definition¶
-
cloneCollection
¶ Copies a collection from a remote
mongod
instance to the currentmongod
instance.cloneCollection
creates a collection in a database with the same name as the remote collection’s database.cloneCollection
takes the following form:Important
You cannot clone a collection through a
mongos
but must connect directly to themongod
instance.cloneCollection
has the following fields:Field Type Description cloneCollection
string The namespace of the collection to rename. The namespace is a combination of the database name and the name of the collection. from
string Specify a resolvable hostname and optional port number of the remote server where the specified collection resides. query
document Optional. A query that filters the documents in the remote collection that cloneCollection
will copy to the current database.
Example¶
This operation copies the profiles
collection from the users
database on the server at mongodb.example.net
. The operation only
copies documents that satisfy the query { active: true }
.
cloneCollection
always copies indexes. The query
arguments is optional.
If, in the above example, the profiles
collection exists in the
users
database, then MongoDB appends documents from the remote
collection to the destination collection.