For your kind information, copyDatabase is now deprecated so now you can use mongodump and mongorestore. Say, for instance, you want to copy the ‘data1’ database from a local instance to ‘data2’ database on the same instance, so for that, you can write the following code:
mongodump --archive="mongodump-data1-db" --db=test
The above code will dump the ‘data1’ database to an archive mongodump-data1-db.
Then you will use mongorestore to restore from the archived database with the help of --nsFrom and --nsTo functions:
mongorestore --archive="mongodump-data1-db" --nsFrom='data1.*' --nsTo='data2.*'
If you wish to learn MongoDB, check out this MongoDB tutorial for free!