JSON 文件的 Mongoimport [英] Mongoimport of JSON file
问题描述
我有一个包含大约 2000 条记录的 JSON 文件.与 mongo 数据库中的一个文档对应的每条记录的格式如下:
I have a JSON file consisting of about 2000 records. Each record which will correspond to a document in the mongo database is formatted as follows:
{jobID:"2597401",
account:"XXXXX",
user:"YYYYY",
pkgT:{"pgi/7.2-5":{libA:["libpgc.so"],flavor:["default"]}},
startEpoch:"1338497979",
runTime:"1022",
execType:"user:binary",
exec:"/share/home/01482/XXXXX/appker/ranger/NPB3.3.1/NPB3.3-MPI/bin/ft.D.64",
numNodes:"4",
sha1:"5a79879235aa31b6a46e73b43879428e2a175db5",
execEpoch:1336766742,
execModify: new Date("Fri May 11 15:05:42 2012"),
startTime: new Date("Thu May 31 15:59:39 2012"),
numCores:"64",
sizeT:{bss:"1881400168",text:"239574",data:"22504"}},
每条记录都在 JSON 文件中的一行中,唯一的换行符位于每条记录的末尾.因此,文档中的每一行都以{jobID:"开头...我正在尝试使用以下命令将这些导入到 mongo 数据库中:
Each record is on a single line in the JSON file, and the only line breaks are at the end of every record. Therefore, each line in the document starts with "{jobID:"... I am trying to import these into a mongo database using the following command:
mongoimport --db dbName --collection collectionName --file fileName.json
但是,我收到以下错误:
However, I get the following error:
Sat Mar 2 01:26:12 Assertion: 10340:Failure parsing JSON string near: ,execModif
0x10059f12b 0x100562d5c 0x100562e9c 0x10025eb98 0x10000e643 0x100010b60 0x10055c4cc 0x1000014b7
0x100001454
0 mongoimport 0x000000010059f12b _ZN5mongo15printStackTraceERSo + 43
1 mongoimport 0x0000000100562d5c _ZN5mongo11msgassertedEiPKc + 204
2 mongoimport 0x0000000100562e9c _ZN5mongo11msgassertedEiRKSs + 12
3 mongoimport 0x000000010025eb98 _ZN5mongo8fromjsonEPKcPi + 1576
4 mongoimport 0x000000010000e643
_ZN6Import8parseRowEPSiRN5mongo7BSONObjERi + 2739
5 mongoimport 0x0000000100010b60 _ZN6Import3runEv + 7376
6 mongoimport 0x000000010055c4cc _ZN5mongo4Tool4mainEiPPc + 5436
7 mongoimport 0x00000001000014b7 main + 55
8 mongoimport 0x0000000100001454 start + 52
Sat Mar 2 01:26:12 exception:BSON representation of supplied JSON is too large: Failure parsing
JSON string near: ,execModif
Sat Mar 2 01:26:12
Sat Mar 2 01:26:12 imported 0 objects
Sat Mar 2 01:26:12 ERROR: encountered 1941 errors
我不知道是什么问题.有人可以推荐解决方案吗?
I do not know what the problem is. Can someone recommend a solution?
推荐答案
我能够使用以下查询修复错误:
I was able to fix the error using the following query:
mongoimport --db dbName --collection collectionName --file fileName.json --jsonArray
希望这对某人有帮助.
这篇关于JSON 文件的 Mongoimport的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!