无法使用mongoimport将.csv导入mongodb [英] Unable to import .csv into mongodb using mongoimport

查看:592
本文介绍了无法使用mongoimport将.csv导入mongodb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一些测试,看看我可以导入一个简单的.csv文件到mongodb,但它mongodb保持返回0对象导入。这是我的步骤:



1)在mongodb / bin中创建一个名为a4.csv的4列和6条记录的简单.csv文件:

 型号价格里程
audi a5 500 500
mercedes cla 333 434
福特555 500
马自达miata 222 434
尼桑370z 111 500
保时捷卡宴333 434

2)运行导入命令:

  ./ mongoimport -d test -c cars --type csv --file a4.csv --headerline 

输出:

  tins-MBP:bin tinzors $ ./mongoimport -d test -c cars --type csv --file a4.csv --headerline 
连接到:127.0.0.1
2015-02-11T12:23:11.656-0500导入0个对象

没有错误,有人可以帮我吗?谢谢!

解决方案

我认为问题在于 csv / p>

a4.csv 文件放置在mongodb bin文件夹中

  Model,Make,Price,Mileage 
audi,a5,500,500
mercedes,cla,333,434
ford,fusion,555,500
mazda,miata,222,434
nissan,370z,111,500
porsche,cayenne,333,434

b
$ b

mongoimport -d test -c cars --type csv --file a4.csv --headerline



输出



D:\MongoDB\MongoDB 2.6 Standard\bin> ; mongoimport -d test -c cars --type csv --file a4.csv --headerline
连接到:127.0.0.1
2015-02-11T23:15:20.631 + 0530导入6个对象

 > db.cars.find()
{_id:ObjectId(54db93a60259aeb2c15b851d),Model:audi,Make:a5,Price:500,Mileage }
{_id:ObjectId(54db93a60259aeb2c15b851e),Model:mercedes,Make:cla,Price:333,Mileage:434}
{ _id:ObjectId(54db93a60259aeb2c15b851f),Model:ford,Make:fusion,Price:555,Mileage:500}
{_id:ObjectId 54db93a60259aeb2c15b8520),Model:mazda,Make:miata,Price:222,Mileage:434}
{_id:ObjectId(54db93a60259aeb2c15b8521 Model:nissan,Make:370z,Price:111,Mileage:500}
{_id:ObjectId(54db93a60259aeb2c15b8522 Make:cayenne,Price:333,Mileage:434}

希望它有帮助。


I am doing some tests to see how I can import a simple .csv file into mongodb but it mongodb keeps returning "0 objects imported. Here are my steps:

1) create a simple .csv file named "a4.csv" in mongodb/bin with 4 columns and 6 records:

Model       Make    Price   Mileage
audi        a5      500     500
mercedes    cla     333     434
ford        fusion  555     500
mazda       miata   222     434
nissan      370z    111     500
porsche     cayenne 333     434

2) Run import command:

./mongoimport -d test -c cars --type csv --file a4.csv --headerline

Output:

tins-MBP:bin tinzors$ ./mongoimport -d test -c cars --type csv --file a4.csv --headerline
connected to: 127.0.0.1
2015-02-11T12:23:11.656-0500 imported 0 objects

There's no error anything. Can someone help me? Thank you!

解决方案

I think problem is in csv file format

a4.csv file placed in mongodb bin folder

Model,Make,Price,Mileage
audi,a5,500,500
mercedes,cla,333,434
ford,fusion,555,500
mazda,miata,222,434
nissan,370z,111,500
porsche,cayenne,333,434

then

mongoimport -d test -c cars --type csv --file a4.csv --headerline

Output

D:\MongoDB\MongoDB 2.6 Standard\bin>mongoimport -d test -c cars --type csv --file a4.csv --headerline connected to: 127.0.0.1 2015-02-11T23:15:20.631+0530 imported 6 objects

> db.cars.find()
{ "_id" : ObjectId("54db93a60259aeb2c15b851d"), "Model" : "audi", "Make" : "a5", "Price" : 500, "Mileage" : 500 }
{ "_id" : ObjectId("54db93a60259aeb2c15b851e"), "Model" : "mercedes", "Make" : "cla", "Price" : 333, "Mileage" : 434 }
{ "_id" : ObjectId("54db93a60259aeb2c15b851f"), "Model" : "ford", "Make" : "fusion", "Price" : 555, "Mileage" : 500 }
{ "_id" : ObjectId("54db93a60259aeb2c15b8520"), "Model" : "mazda", "Make" : "miata", "Price" : 222, "Mileage" : 434 }
{ "_id" : ObjectId("54db93a60259aeb2c15b8521"), "Model" : "nissan", "Make" : "370z", "Price" : 111, "Mileage" : 500 }
{ "_id" : ObjectId("54db93a60259aeb2c15b8522"), "Model" : "porsche", "Make" : "cayenne", "Price" : 333, "Mileage" : 434 }

Hope it helps.

这篇关于无法使用mongoimport将.csv导入mongodb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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