如何使用 mongoimport 导入 csv [英] How to use mongoimport to import csv
本文介绍了如何使用 mongoimport 导入 csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试导入包含联系信息的 CSV:
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 说 imported 1 个对象
,但是启动 Mongo shell 并运行 db.things.find()
并没有显示任何新文档.
Trace says imported 1 objects
, but firing up the Mongo shell and running db.things.find()
doesn't show any new documents.
我错过了什么?
推荐答案
您的示例适用于 MongoDB 1.6.3 和 1.7.3.下面的示例适用于 1.7.3.您使用的是旧版本的 MongoDB?
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?
$ 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 }
这篇关于如何使用 mongoimport 导入 csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文