How to use mongoimport to import csv

2019-01-03 19:25发布

Trying to import a CSV with contact information:

Name,Address,City,State,ZIP  
Jane Doe,123 Main St,Whereverville,CA,90210  
John Doe,555 Broadway Ave,New York,NY,10010 

Running this doesn't seem to add any documents to the database:

$ mongoimport -d mydb -c things --type csv --file locations.csv --headerline

Trace says imported 1 objects, but firing up the Mongo shell and running db.things.find() doesn't show any new documents.

What am I missing?

17条回答
再贱就再见
2楼-- · 2019-01-03 19:56

Robert Stewart have already answered for how to import with mongoimport.

I am suggesting easy way to import CSV elegantly with 3T MongoChef Tool (3.2+ version). Might help someone in future.

  1. You just need to select collection
  2. Select file to import
  3. You can also unselect data which is going to import. Also many options are there.
  4. Collection imported

See how to import video

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-01-03 19:56
1]We can save xsl as .csv file
2] Got to MongoDB bin pathon cmd - > cd D:\Arkay\soft\MongoDB\bin
3] Run below command
> mongoimport.exe -d dbname -c collectionname --type csv --file "D:\Arkay\test.csv" --headerline
4] Verify on Mongo side using below coomand.
>db.collectioname.find().pretty().limit(1)
查看更多
Explosion°爆炸
4楼-- · 2019-01-03 19:59

C:\wamp\mongodb\bin>mongoexport --db proj_mmm --collection offerings --csv --fieldFile offerings_fields.txt --out offerings.csv

查看更多
爷、活的狠高调
5楼-- · 2019-01-03 20:02

Just use this after executing mongoimport

It will return number of objects imported

use db
db.collectionname.find().count()

will return the number of objects.

查看更多
姐就是有狂的资本
6楼-- · 2019-01-03 20:03

For the 3.4 version, please use the following syntax:

mongoimport -u "username" -p "password" -d "test" -c "collections" --type csv --file myCsv.csv --headerline

After 3 days, I finally made it on my own. Thanks to all the users who supported me.

查看更多
登录 后发表回答