如何使用mongoimport导入csv [英] How to use mongoimport to import csv

查看:144
本文介绍了如何使用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

跟踪说导入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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆