我正試圖按照本文中的步驟http://zaiste.net/2012/08/importing_json_into_mongodb/將名爲breedData.json的文件導入到mongodb中。mongoimport未能導入JSON數據
所以我在終端從我的應用的根文件夾中輸入下面的命令。 breedData.json文件也位於應用程序根文件夾中。 Mongod和nodemon正在運行。
mongoimport --db shelterdoggie --collection breeds --type json --file breedData.json --jsonArray
,我得到這個:
我檢查了我的文件,jsonlint.com,它是有效的JSON。
我使用上述終端命令這個JSON格式的嘗試:
[
{"malehw":"Ht: 9-11.5, Wt: 7-9","femalehw":"Ht: 9-11.5, Wt: 7-9"},
{"malehw":"Ht: 27, Wt: 60","femalehw":"Ht: 25, Wt: 50"},
{"malehw":"Ht: 23, Wt: 45","femalehw":"Ht: <23, Wt: 45"}
]
,我也試過這種格式,而上面留下關閉--jsonArray標誌命令:
{"malehw":"Ht: 9-11.5, Wt: 7-9","femalehw":"Ht: 9-11.5, Wt: 7-9"}
{"malehw":"Ht: 27, Wt: 60","femalehw":"Ht: 25, Wt: 50"}
{"malehw":"Ht: 23, Wt: 45","femalehw":"Ht: <23, Wt: 45"}
但後來我得到這個錯誤:
2015-09-07T01:11:00.034-0700 connected to: localhost
2015-09-07T01:11:00.035-0700 Failed: error processing document #1: invalid character '{' after array element
2015-09-07T01:11:00.035-0700 imported 0 documents
我檢查了該文件,並有152 {'S和152},我在文件中有152行/文檔,所以它不應該是由於某個地方沒有封閉的大括號。我不明白爲什麼這不起作用。如果您有任何建議,我會很感激。
下面是情況下,從我以.json文件一個全線它可以幫助:
{"malehw":"Ht: 24-26, Wt: 75-95","femalehw":"Ht: 22-24, Wt: 75-95","catfriendly":"••••","easytraining":"••••••","watchdog":"••••••","grooming":"•••","coldtolerant":"••••","care":"Among the most intelligent of breeds, the German Shepherd Dog is so intent on his mission whatever that may be and he is virtually unsurpassed in working versatility. He is utterly devoted and faithful. He is usually good with other pets.","breed":"German Shepherd Dog","health":"This breed needs daily mental and physical challenges. He enjoys a good exercise session as well as learning session. He is family-oriented and does well as a house dog. His coat needs brushing one or two times weekly.","energy":"••••","playfulness":"•••","dogfriendly":"••","strangerfriendly":"•••","protection":"••••••","heattolerant":"••••","exercise":"•••••","affection":"••••","index":67,"url":"https://www.petfinder.com/dog-breeds/German-Shepherd-Dog"}
我能夠運行所有的疑問沒有任何錯誤,甚至我創建了一個完整的最後一行數組(剛剛複製同一行),並且它仍然在我的shell中正常工作。檢查你是否指的是正確的文件和路徑。 –
另外,我正在使用MongoDB shell版本:3.0.4。我正在從shelter_doggie目錄運行終端命令,而breedData.json文件位於頂級目錄中。我也嘗試將數據導出爲csv文件並使用以下格式導入:'mongoimport -db shelterdoggie --collection breeds --type csv --file kimonoData.csv --headerline'但是我得到了這個錯誤'error validating settings:incompatible options: - 文件和位置參數(s)' – Amanda