Hello there, I’m going to show you how to Export MongoDB collections. Let’s just started, here is the basic command for exporting mongoDB collection:
mongoexport --db=database_name --collection=collection_name --out=output_filename.json
that was the basic command line for MongoDB Export. But, if you have authentication for the database you created and the database it’s not on your PC. You can use this for the username, password, host, port:
mongoexport --db=database_name --collection=collection_name --out=output_filename.json --username=database_username --password=database_password --host=hostname --port=27017
Let’s break them down for each parameters:
- — db : database name, of course you have already know it.
- — collection : which collection you would like to export.
- — out : what is the output filename of the collection you just export, *.json is the format for the file.
- — username : username to/for control your database.
- — password : password of the username above.
- — host : by default it is (localhost), but you can change it to somewhere else.
- — port : by default it is (27017), change to the port where you have installed the MongoDB
Okay, that’s all for export mongoDB collections