- Reference >
- Database Commands >
- copydb
copydb¶
-
copydb
¶ The
copydb
command copies a database from a remote host to the current host. The command has the following syntax:All of the following arguments are optional:
- slaveOk
- username
- nonce
- key
You can omit the
fromhost
argument, to copy one database to another database within a single MongoDB instance.You must run this command on the destination, or the
todb
server.Be aware of the following behaviors:
copydb
can run against a slave or a non-primary member of a replica set. In this case, you must set theslaveOk
option totrue
.copydb
does not snapshot the database. If the state of the database changes at any point during the operation, the resulting database may be inconsistent.You must run
copydb
on the destination server.The destination server is not locked for the duration of the
copydb
operation. This means thatcopydb
will occasionally yield to allow other operations to complete.If the remote server has authentication enabled, then you must include a username, nonce, and a key. The nonce is a one-time password that you request from the remote server using the
copydbgetnonce
command. Thekey
is a hash generated as follows:If you need to copy a database and authenticate, it’s easiest to use the shell helper: