- Reference >
- Database Commands >
- copydb
copydb¶
-
copydb¶ The
copydbcommand 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
fromhostargument, to copy one database to another database within a single MongoDB instance.You must run this command on the destination, or the
todbserver.Be aware of the following behaviors:
copydbcan run against a slave or a non-primary member of a replica set. In this case, you must set theslaveOkoption totrue.copydbdoes 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
copydbon the destination server.The destination server is not locked for the duration of the
copydboperation. This means thatcopydbwill 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
copydbgetnoncecommand. Thekeyis a hash generated as follows:If you need to copy a database and authenticate, it’s easiest to use the shell helper: