Back

Explore Courses Blog Tutorials Interview Questions
0 votes
5 views
in SQL by (47.6k points)

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?

1 Answer

0 votes
by (106k points)

By following the way you can use mongoimport to import 

csv$ cat > locations.csv 

Name,Address,City,State,ZIP 

Jane Doe,123 Main St,Whereverville,CA,90210 

John Doe,555 Broadway Ave,New York,NY,10010 

Ctrl-d

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

connected to: 127.0.0.1 

imported 3 objects 

$ mongo MongoDB shell version: 1.7.3 

connecting to: test 

> use mydb 

switched to db mydb 

> db.things.find() 

{ "_id" : ObjectId("4d32a36ed63d057130c08fca"), "Name" : "Jane Doe", "Address" : "123 Main St", "City" : "Whereverville", "State" : "CA", "ZIP" : 90210 } 

{ "_id" : ObjectId("4d32a36ed63d057130c08fcb"), "Name" : "John Doe", "Address" : "555 Broadway Ave", "City" : "New York", "State" : "NY", "ZIP" : 10010 } 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
2 answers
asked Sep 9, 2019 in SQL by Sammy (47.6k points)
0 votes
1 answer
asked Jul 11, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Jan 7, 2021 in SQL by Appu (6.1k points)

Browse Categories

...