It's a general need in MongoDB development, to take backups or restore DB with an old backup. DB backup can be done at both DB level and individual Collection level. Let's see how we can perform different backup/restore operations.. DB Backup Complete DB Assuming database to backup is "mydb", the best thing is to back it as gzip to save some space on your Server. mongodump -- archive = mydb . 2017 - 09 - 21.gz -- gzip -- db mydb This will create the archive in the directory where you're executing the command. Another way is to take backup as bson documents. mongodump -h localhost -p 27017 -d mydb -o C:\mongobackup\20170921 A directory with db name will be created under C:\mongobackup\20170921 In case you have multiple instances running on same server, you can use --host and --port options. Individual Collection mongodump -- collection myCollection -- db mydb This will create backup with same name as that of collection (myCollection in this
There are different ways you can install MongoDB as Windows Service.. Using mongod mongod -- config "M:\mongodb\conf\mongod.cfg" -- serviceName "MongoDB" -- serviceDisplayName "MongoDB" -- serviceDescription "MongoDB Server Instance" -- install mongod -- logpath M : \mongodb\data\log\mongo . log -- dbpath M : \mongodb\data\db -- auth -- directoryperdb -- install Specifying argument directoryperdb creates separate directory structure for different DBs like admin, mydb etc. Using Windows Service command sc . exe create MongoDB binPath = "\"M:\mongodb\bin\mongod.exe\" --service --config=\"M:\mongodb\mongod.cfg\"" DisplayName = "MongoDB" start = "auto" Following the Windows service command, make sure Service console is not opened. Start/Stop MongoDB Service net start MongoDB net stop MongoDB Deleting MongoDB Service mongod --remove sc.exe delete MongoDB