CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > How to > How to export MongoDB data into CSV file?

How to export MongoDB data into CSV file?

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Published: August 31, 2020 · 1 min read · 0 Comments
Share: X in 🔗
coding coffee

We may need to export MongoDB data into CSV from local server or remote server. Hence, in this post we can learn how to do it.

export MongoDb data into CSV

Export MongoDB data into CSV from local server with given fields with header name:

mongoexport --db my_db_name --collection my_collection_name --type=csv --fields field1,field2,field3 --out my_exported_csv_file_name.csv

If you want to export without header then use –noHeaderLine:

Example:

mongoexport --db my_db_name --collection my_collection_name --type=csv --fields field1,field2,field3 --out my_exported_csv_file_name.csv --noHeaderLine

If you want to export from remote server you need to install mongo-tools package using following command:

sudo apt install mongo-tools

And use the following script

mongoexport --host=myhost.com --port=27017 --db=my_db_name --collection=my_collection_name --type=csv --fields=field1,field2,field3 --out my_exported_csv_file_name.csv --noHeaderLine

Note: If you get unrecognized field ‘snapshot’ during the mongoexport. It may be due to missmatch version of mongoexport tool and mongo db server. In this case, we have to include –forceTableScan parameters.

mongoexport --host=myhost.com --port=27017 --db=my_db_name --collection=my_collection_name --type=csv --fields=field1,field2,field3 --out my_exported_csv_file_name.csv --noHeaderLine --forceTableScan

Related Posts:

  • How to Import and Export Data in MongoDB: A…
  • MySQL Commands for Developers
  • How to Solve “systemctl command not found” Error: A…
  • How to Connect Java Application to a Remote Database…
  • How to Fix SSH Agent Forwarding on macOS: The…
  • Install MongoDB BI Connector on Ubuntu
Tags:devopsmongodb
Was this article helpful?
← Previous ArticleString Interpolation In Jenkins
Next Article →How to Check MongoDB Database size?

Leave a Comment Cancel reply

You must be logged in to post a comment.

Recent Posts

  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
  • Complete Guide to JaCoCo: How to Measure Java Code Coverage Accurately
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
© 2026 CoderSathi. All rights reserved. Privacy Policy · Sitemap