A simple command will help to import and export collections in mongoDB.
Export/Dump Collections in MongoDB:
mongodump -d <database_name> -o <directory_backup>
The above command will dump all the collections in the defined directory.
eg: if your database name is awesome_db and you selected the my_db_backup as backup directory then you need run below command:
mongodump -d awesome_db -o my_db_backup
If your db has authentication enabled then pass -u <username> -p <press enter> with the above command.
Import/Restore Collection in MongoDB:
mongorestore -d <database_name> <directory_backup>
Similarly this command will restore the collections in the mongodb database. for eg:
mongodump -d awesome_db -o my_db_backup
pass the authentication -u <username> -p <press enter> if your mongodb has authentiction.
Comments
Post a Comment