Step-by-Step Tutorial: How to Backup and Restore MongoDB Databases 2023

Step-by-Step Tutorial: How to Backup and Restore MongoDB Databases 




Step 1:

  •     Check MongoDB Command Line Database Tools downloaded or not.
  •     Go to "C:\Program Files\MongoDB" and theck wheather Tools folder is present or only Server      folder is there.
            


  •   If present then go to step 3 otherwise go to step 2 for download and install MongoDB     Command  Line Database Tools.

Step 2:

  •  Go to this link : " https://www.mongodb.com/try/download/database-tools "   and scroll below on this page to find MongoDB Command Line Database Tools Download or ctrl+f then paste there MongoDB Command Line Database Tools Download  ,this will take you to Download option.
  • The change and set the package,platform and version options as I have set in below screenshot then CLICK ON Download Button. After download install the same.
          


Step 3:    

  •     After install open Edit the system environment variable by searching on Windows search "env".


  • Then go to "Environment variables" and after that go to path under "System variables".
  • Then go to inside "C:\Program Files\MongoDB\Tools\100\bin"  and copy this bin path and paste inside path of System variables by adding New path.
  • After adding rhis path now open Command Prompt again and run this command :   mongodump --version .
  • If the version details comes then Congrats  you have set up all things successfully.

Step 4:

  •     Then go to that folder or create a new one where you want to Save the backup files. 
  •     From this location open Command Prompt by just typing CMD like below and hit enter.


  • After CMD opens run command "mongosh DB_URI" to coonect with your database then do the further steps.
  • Then  run this command on command prompt :   mongodump --uri="connection URI" --db=database name   ,   with your own database url .
  • After this step a dump folder will be created having the database named folder inside and that database folder contains all the collections data.
  • Now final step i.e, Restore the saved data to target database.

Step 5:

  • Now run the below command by providing your own details and data will be restore successfully to targetted database.
  • Command :     mongorestore --uri=<connection-uri> --db=<database-name> <dumpped path>
  • Eg :     mongorestore --uri="mongodb://localhost:27017" --db=test "C:\Demo Project\Mongo\dump\test"
  • Here on above example I am restoring the dumpped data to my local database where "test" is my database name and "C:\Demo Project\Mongo\dump\test" is the path where all collection's data lies.
  • Finally you will get result like below screenshot.

 " 
            So,try this and make RESTORE And BACKUP easy in MongoDB without taking any                    third party application's membership.
 "

Comments