Project needs, import local json data into mongodb, use the command under cmd
mongoimport -d datas -c title --file E:\title.json
The following error occurred
Failed: invalid JSON input.
I checked the information and researched it and found that it was a problem with the
original data format. The original data is:
{
"_id" : ObjectId("5be19b932ab79c00013074ed"),
"workNumber" : "2016223045999",
"titles" : "李浩,发的是达到顶峰",
"_class" : "cn.bookcycle.scuservice.pojo.TitlePO"
}
Where the first line
“_id” : ObjectId(“5be19b932ab79c00013074ed”),
It is in the format of json v1.0
and the mongodb version I use is 4.2. The official website says that starting from 4.2, Json v2.0
should be in the following format by default
{
"_id":{
"$oid":"5be19b932ab79c00013074ed"},
"workNumber":"2016223045999",
"titles":"李浩,发的是达到顶峰",
"_class":"cn.bookcycle.scuservice.pojo.TitlePO"
}
Therefore, the import fails
Solution:
Use --legacy to identify json v1.0
mongoimport -d datas -c title --file E:\title.json --legacy