我是mongoDB的新手,我想将数据导入Mongodb。我的文件名为data.json
,它具有以下架构:
{
"0ja80AEnHtP2L5dQY3VthnUsBWY2" : {
"-LClYVRHxDL0swrpRnbD" : {
"date" : "2018-10-22T07:33:33Z",
"sequence" : [ "task1", "task1", "task1", "task1", "task1" ]
}
},
"0lFQht4tdigZ8hmI8Kq54lxaRHx1" : {
"-LClYVRJ7KYWZjudkhNr" : {
"date" : "2018-06-03T06:01:44Z",
"sequence" : [ "task1", "task1", "task1", "task1", "task1" ]
}
},
... (more data)
}
所以主要问题是当我执行以下命令时:
mongoimport --db dbName --collection clName --type json --file data.json
它说文档已导入1,当我检查我的收藏集时,我看到整个文件都作为一个文档导入了。
答案 0 :(得分:0)
您的示例JSON似乎是一个json对象,这就是您仅获得一个文档的原因。
[{
"-LClYVRHxDL0swrpRnbD" : {
"date" : "2018-10-22T07:33:33Z",
"sequence" : [ "task1", "task1", "task1", "task1", "task1" ]
}
},
{
"-LClYVRJ7KYWZjudkhNr" : {
"date" : "2018-06-03T06:01:44Z",
"sequence" : [ "task1", "task1", "task1", "task1", "task1" ]
}
},
... (more data)
]
尝试上述建议的更改,然后尝试通过在导入字符串中添加--jsonArray来导入它。