How do you copy entire MongoDB database?

I faced small problem how to duplicate entire MongoDB database and I tried just to rename folder under data directory. So, instead of having my_database I just renamed it to my_new_database but it didn’t helped and when I used show collections it returned me an empty set.
I also tried to rename files inside data/my_database to my_new_database but this didn’t helped me either.

So, I finally looked into the documentation and found this command which copies the entire database:



db.copyDatabase("my_database", "my_new_database", "localhost")


You may also like