MongoDB Export via Terminal / Command Line

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.

Okay, that’s all for export mongoDB collections

I wrote these tutorials for myself in future when I forget for the next steps.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store