我只是想問問我怎麼能導入新的MongoDB這個example.json文件我希望讓每個seassion對象行中我試圖導入JSON文件
mongoimport --db foo --collection myCollections < dataBuys.json
2015-05-07T21:19:15.828+0300 connected to: localhost
2015-05-07T21:19:18.831+0300 foo.myCollections 168.5 MB
2015-05-07T21:19:21.826+0300 foo.myCollections 168.5 MB
2015-05-07T21:19:24.828+0300 foo.myCollections 168.5 MB
2015-05-07T21:19:27.828+0300 foo.myCollections 168.5 MB
2015-05-07T21:19:28.849+0300 warning: attempting to insert document with size 124.6 MB (exceeds 16.0 MB limit)
2015-05-07T21:19:28.986+0300 error inserting documents: write tcp 127.0.0.1:27017: broken pipe
2015-05-07T21:19:28.986+0300 imported 0 documents
,這表
mongoimport -d mydb -c mycollection --jsonArray < dataBuys.json
2015-05-07T21:20:02.139+0300 connected to: localhost
2015-05-07T21:20:02.139+0300 Failed: error reading separator after document #1: bad JSON array format - found no opening bracket '[' in input source
2015-05-07T21:20:02.139+0300 imported 0 documents
我要導入的文件具有以下格式,其大小爲170mb,而另一個爲2.97GB。
{
"Sessions": {
"420374" : {
"Purchases" : [
{
"Price" : "12462",
"Quantity" : "1",
"Timestamp" : "2014-04-06T18:44:58.314Z",
"ItemId" : "214537888"
},
{
"Price" : "10471",
"Quantity" : "1",
"Timestamp" : "2014-04-06T18:44:58.325Z",
"ItemId" : "214537850"
}
]
},
"281626" : {
"Purchases" : [
{
"Price" : "1883",
"Quantity" : "1",
"Timestamp" : "2014-04-06T09:40:13.032Z",
"ItemId" : "214535653"
}
]
},
"420368" : {
"Purchases" : [
{
"Price" : "6073",
"Quantity" : "1",
"Timestamp" : "2014-04-04T06:13:28.848Z",
"ItemId" : "214530572"
},
{
"Price" : "2617",
"Quantity" : "1",
"Timestamp" : "2014-04-04T06:13:28.858Z",
"ItemId" : "214835025"
}
]
}
}
}
我必須重新格式化json嗎?是否有可能使它像這樣工作?
我認爲帕特是正確的,您目前的格式將無法正常工作。在這裏查看另一種替代格式:http://stackoverflow.com/a/16677630/371273 –
所以簡單的答案是mongodb無法以這種格式導入json它應該是與像這樣的對象的行數組{{「stupid」: 「bla bla」,「megaStupid 」:「bla bla」} –