![]() ![]() Note: If the collection name is not specified then the collection name is created based on the first name of the file. ![]() Using these steps you can also import TSV files, simply using –type tsv. In MongoDB, we can also import csv file into two ways:ġ. We have the following CSV file called student.csv: Mongoimport –db database_name –collection collection_name –type csv –file file_location –header With header row: We can import data with header row with the help of –header that shows the name of the fields will use the first line of the CSV file. Mongoimport –db gfg –collection student –type csv –file H:\students.csv –headerĢ. Without header row: We can import data without header row by excluding –header. Mongoimport –db database_name –collection collection_name –type csv –fields field_names –file file_location But in the place of the header, we have to put –fields that show the name of the field that we want to give. Mongoimport –db gfg –collection student –type csv –fields name,age –file H:\students.Every once in a while, I need to give a non-technical user (like a business analyst) data residing in MongoDB consequently, I export the target data as a CSV file (which they can presumably slice and dice once they import it into Excel or some similar tool). 5120X1440P 329 DAYZ BACKGROUND HOW TOMongo has a handy export utility that takes a bevy of options, however, there is an outstanding bug and some general confusion as to how to properly export data in CSV format.Īccordingly, if you need to export some specific data from MongoDB into CSV format, here’s how you do it. The key parameters are connection information to include authentication, an output file, and most important, a list of fields to export. What’s more, you can provide a query in escaped JSON format. You can find the mongoexport utility in your Mongo installation bin directory. I tend to favor verbose parameter names and explicit connection information (i.e. Rather than a URL syntax, I prefer to spell out the host, port, db, etc directly). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |