How does MongoDb display collection data
Using Mongoimport to import CSV
Trying to import a CSV with contact information:
When you do this, no documents appear to be added to the database:
Trace says, but starting the Mongo shell and running it doesn't show any new documents.
What am i missing
Your example worked for me with MongoDB 1.6.3 and 1.7.3. Example below was for 1.7.3. Are you using an older version of MongoDB?
I was confused about a similar issue where mongoimport gave me no error but reported importing 0 records. I had saved my file, which did not work with OSX Excel for Mac 2011 version, using the standard "Save As ..." "xls as csv" format without specifically specifying the "Windows Comma Separated (.csv)" format . After researching this site and trying the "Save As" format with "Windows Comma Separated (.csv)" again, mongoimport worked fine, I think mongoimport expects a newline character on every line, and Mac's standard CSV export Excel 2011 did not provide these characters at the end of each line.
We need to run the following command:
-d is the database name
-c is the name of the collection
--headerline If you use --type csv or --type tsv, the first line is used as the field name. Otherwise, mongoimport imports the first line as a separate document.
For more information: Mongo import
You will most likely need to authenticate if you are working in production environments. You can use something like this to authenticate to the correct database with the appropriate credentials.
Make sure there is a blank line at the end of the file. Otherwise the last line is ignored in some versions of mongoimport
I use this on Mongoimport Shell
Type can choose csv / tsv / json, but only csv / tsv can use
You can read more about the official document.
Robert Stewart already answered how to import with mongoimport.
I suggest an easy way to import CSV elegantly using 3T MongoChef Tool (version 3.2+). Might help someone in the future.
- All you have to do is select the collection
- Select the file to import
- You can also deselect the data to import. There are also many options.
- Collection imported
See how to import videos
First you should get out of the shell and then run the command like this:
Use the following syntax for version 3.4:
After 3 days I finally made it on my own. Thank you to all of the users who supported me.
An error message was displayed when trying to import the CSV file. What have I done. First, I changed the header column names to uppercase and removed "-" and added "_" if necessary. Then enter the following command to import CSV to Mongo
C: \ wamp \ mongodb \ bin> mongoexport --db proj_mmm - collection offers --csv --fieldFile offers_fields.txt --out offers.csv
Just use this after running mongoimport
The number of imported objects is returned
returns the number of objects.
mongoimport -d test -c test --type csv --file SampleCSVFile_119kb.csv --headerline
Check collection data: -
Oddly enough, nobody mentioned the flag:
Share for future readers:
In our case we had to add the parameter to make it work
My requirement was to import that into a remote instance. Worked for me for the following command:
Below is the screenshot of what it looks like after importing:
where and are the columns in the file.
At the specified file that only has one column without a header , the following command worked for me:
There field name refers to the header name the column in the file.
Make sure to copy the CSV file to / usr / local / bin or the folder where your Mondodb is located
- Beliefs must be religious
- What are the powers of the task master
- Are books currently banned in Poland?
- How are NCERT sample books useful?
- Nuclear war is justified
- Why are people interested in art
- Can chickens be a boy
- What is THC-free hemp oil
- When to use Hadoop vs SQL
- How does Amazon work
- Who were Shmi Skywalker's parents
- What does Garu
- What is system software
- How can I track my stolen iPhone?
- How can I prove 1 2 1
- Why did you get into crypto
- What is sosh
- Can you drive without a driver's license
- Why do artists publish EPs
- How to make a sarcastic emoji
- What is the healthiest body soap cleaner
- What item is in stained glass
- How complete is the Apple ecosystem
- What are the benefits of studying biomedical engineering