我有一个json文件,如下所示:
{"_id":"id1","cat":["C","D","R","P"],"desc":"some desc","name":"some_name","category":"categ","languages":["en"],"type":"swf","start_date":1.39958850681748E9},
{"_id":"toy-driver","cat":["C","D","R","P"],"desc":"some desc","name":"name2","category":"Rac","languages":["en"],"type":"swf","start_date":1.399588506820609E9},
............
它包含大约900行。当我碰巧使用命令导入2或3个相似的行时:
mongoimport -d test -c test --jsonArray file.json
它完美导入没有任何错误,而导入整个文件会导致一些错误。
imported 0 objects
encountered 1 error
答案 0 :(得分:0)
如果我没弄错的话,这里有两个问题。
--jsonArray
需要1个JSON文档,其中所有900条记录都是单个数组的一部分
您从一个文件中提供了900个独立的JSON行,这些行没有回答--jsonArray格式。 (另外,在每行末尾放下逗号,mongoimport期待换行符。--file file.json
我相信如果您删除了--jsonArray参数并添加了--file关键字,那就没问题了。例如: -
mongoimport -d test -c test --file file.json
file.json与此类似:
{"_id":"id1","cat":["C","D","R"], ... "type":"swf","start_date":1.39958850681748E9}
{"_id":"id2","cat":["C","D","R"], ... "type":"swf","start_date":1.39958850681748E9}
{"_id":"id3","cat":["C","D","R"], ... "type":"swf","start_date":1.39958850681748E9}
希望这有帮助!