我有这样的json_file.json:
[
{
"project": "project_1",
"coord1": 2,
"coord2": 10,
"status": "yes",
"priority": 7
},
{
"project": "project_2",
"coord1": 2,
"coord2": 10,
"status": "yes",
"priority": 7
},
{
"project": "project_3",
"coord1": 2,
"coord2": 10,
"status": "yes",
"priority": 7
}
]
当我运行以下命令将此导入到mongodb中时:
mongoimport --db my_db --collection my_collection --file json_file.json
我收到以下错误:
Failed: error unmarshaling bytes on document #0: JSON decoder out of sync - data changing underfoot?
如果我在命令中添加--jsonArray标志,则如下所示:
imported 3 documents
而不是原始文件中所示的json格式的一个文档。
如何使用上面显示的文件中的原始格式将json导入到mongodb中?
以下来自MongoDB项目博客的参考可以帮助您深入了解数组在Mongo中的工作方式:
https://blog.mlab.com/2013/04/thinking-about-arrays-in-mongodb/
否则,我将为您导入文件,或者:
a)使用--jsonArray标志将三个不同的对象分别导入到集合中;要么
b)将完整的数组封装在单个对象中,例如,以这种方式:
{
"mydata":
[
{
"project": "project_1",
...
"priority": 7
}
]
}
HTH。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句