EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials MongoDB Tutorial MongoDB Export to Excel
 

MongoDB Export to Excel

Updated March 14, 2023

MongoDB Export to Excel

 

 

Introduction to MongoDB Export to Excel

MongoDB export to excel is defined as the export of the collected data into the CSV file in MongoDB; we can export the specific field or all field data of collection into excel or CSV file. We can export the data by using the mongo export command. We can also export the collected data into the JSON or TSV file. Mongo export is the utility of the MongoDB server, which was located in the bin directory.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

How to Export Data to Excels in MongoDB using Various Methods?

Below are the various methods of data export into excel available in MongoDB.

1. Export the whole Collection Data into the CSV or Excel File

  • We can export the whole collection data into the CSV file by using the mongoexport command are as follows.
  • Below is the example of exporting whole collection data into the CSV file using the mongoexport command.

Syntax:

  • Mongoexport
  • –host (host name of database server)
  • -u (name of the user which was used to export the data into the file.)
  • -p (password of the user which was used to export the data into the file.)
  • –db (Name of database which was used to export the data into the file.)
  • –collection (name of collection which was used to export the data into the file.)
  • –out /name_of_file (Name of file which was we have used to export the data from collection to file.)

Example:

Below is the example of export the whole collection data into the CSV file in MongoDB.

Command:

mongoexport --db admin --collection import1 --out test.csv
cat test.csv

Output:

MongoDB Export to Excel Example 1

  • In the above example, we have exported import1 collection data into the test.csv file by using the mongoexport command.
  • We have used the database name as admin and collection name as import1.
  • We have used the output file name as test.csv to export the data from the collection into the file.

2. Export the Specified querycollection Data into the CSV or Excel File

  • We can export the specified querycollection data into the CSV file using the mongoexport command.
  • Below is the example of export specified query collection data into the CSV file by using the mongoexport command.

Syntax:

  • Mongoexport
  • –host (host name of database server)
  • -u (name of the user which was used to export the data into the file.)
  • -p (password of the user which was used to export the data into the file.)
  • –db (Name of database which was used to export the data into the file.)
  • –collection (name of collection which was used to export the data into the file.)
  • –query ‘{“field_name (field name which was we have used with mongoexport command)”: “document name”}.’
  • –out /name_of_file (Name of file which was we have used to export the data from collection to file.)

Example:

Below is the example of export the specified query collection data into the CSV file in MongoDB.

Command:

mongoexport --db admin --collection import1 --query '{"item": "paper"}' --out test1.csv
cat test1.csv

Output:

MongoDB Export to Excel Example 2

  • In the above example, we have exported import1 collection data into the test1.csv file by using the mongoexport command.
  • We have used the database name as admin and collection name as import1.
  • We have used the output file name as test1.csv to export the data from the collection into the file.
  • We have exported only which document which contains the name as paper.

3. Export the Specified fieldcollection data into the CSV or Excel File

  • We can export the specified field collection data into the CSV file by using the mongoexport command are as follows.
  • Below is the example of export specified field collection data into the CSV file by using the mongoexport command.

Syntax:

  • Mongoexport
  • –host (host name of database server)
  • -u (name of the user which was used to export the data into the file.)
  • -p (password of the user which was used to export the data into the file.)
  • –db (Name of database which was used to export the data into the file.)
  • –collection (name of collection which was used to export the data into the file.)
  • –fields (field name used to export the data into CSV file.)
  • –out /name_of_file (Name of file which was we have used to export the data from collection to file.)

Example:

Below is the example of export the specified field collection data into the CSV file in MongoDB.

Command:

mongoexport --db admin --collection import1 --fields _id,item,qty,size --out test2.csv
cat test2.csv

Output:

MongoDB Export to Excel Example 3

4. Export the collected data into the CSV or Excel file using Limit

  • We can export the collected data into the CSV file by using the mongoexport command are as follows.
  • Below is the example of export collection data into the CSV file by using limit.

Syntax:

  • Mongoexport
  • –host (host name of database server)
  • -u (name of the user which was used to export the data into the file.)
  • -p (password of the user which was used to export the data into the file.)
  • –db (Name of database which was used to export the data into the file.)
  • –collection (name of collection which was used to export the data into the file.)
  • –limit (Number of documents which was we have exporting into the file.)
  • –out /name_of_file (Name of file which was we have used to export the data from collection to file.)

Example:

Below is the example of export the whole collection data into the CSV file.

Command:

mongoexport --db admin --collection import1 --limit 4 --out test_exp.csv
cattest_exp.csv

Output:

MongoDB Export to Excel Example 4

Recommended Article

This is a guide to MongoDB Export to Excel. Here we discuss Introduction and how to Export Data to Excel in MongoDB using Various Methods along with its different Commands and its examples. You can also go through our other suggested articles to learn more –

  1. How Does Collection Method Works in MongoDB?
  2. MongoDB Alternatives | Top 8
  3. Lookup in MongoDB With Characteristics
  4. MongoDB Limit() | How to Works?

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW