We'll list down here some helpful MongoDB commands these are helpful and requires in day job!
Sometimes it requires to dump all the collections or specified one's
I'm gonna mention here how you can get backup (dump) file from MongoDB for each collections
Let's say you want to take a backup for users
colleciton for that the command will be like below
mongoexport --uri="mongodb+srv://[username]:[password]@cluster0.dtwwj.mongodb.net/[database_name]" --collection=users --out=users.json
The command above self descriptive, on --collection
param we're providing our target collection name then on --out
we're simply naming
the file that would should be exported as.
to import mongoDB collections from json file we simply use the mongoimport
utility provides with mongo cli
the format should be something like this (we'll use MongoDB cloud in this example)
mongoimport --uri "mongodb+srv://[username]:[password]@cluster0.dtwwj.mongodb.net/[database_name]" users.json
where users.json
is
the dump file from your backup, we're just restoring the backup