2

How can I export my whole database using command?

I have tried to export collections from mongoDB compass and it's works.
But I want to export whole DB using command.
sohil vaghasiya
  • 533
  • 1
  • 5
  • 13
  • mongodump is a good way to take a dump of the entire database. Not sure if MongoDB compass has commandline access. https://docs.mongodb.com/manual/reference/program/mongodump/ – Jayadevan Aug 07 '19 at 09:35
  • See here (https://stackoverflow.com/questions/11255630/how-to-export-all-collections-in-mongodb) – Null Pointer Aug 09 '19 at 08:13

1 Answers1

8

I got an answer. We can do export & import whole mongodb database with command from CMD.

1.Open CMD run as administrator.

2.Go to your mongo's bin directory. ex.C:\Program Files\MongoDB\Server\4.0\bin

3.Hit the command for export database.

mongodump --archive=DBName.gz --gzip --db DBName

4.Hit the command to restore database.

mongorestore --gzip --archive=DBName.gz --db DBName
sohil vaghasiya
  • 533
  • 1
  • 5
  • 13