打算把公司登陆系统现在还是直接使用数据库进行查询,今天打算把它优化一下换成 MongoDB 进行查询,结果导入测试数据的时候一直报 Failed: error processing document #2: invalid character ',' looking for beginning of value 错误,搞了大半天才解决,它喵的。
[root@iZm5ec7pkk6xphure3pgf5Z bin]# ./mongoimport -h localhost:9085 -c gm_users -d api --mode upsert --file gm_user1.json
2019-04-08T15:52:52.307+0800 connected to: localhost:9085
2019-04-08T15:52:52.307+0800 Failed: error processing document #2: invalid character ',' looking for beginning of value
2019-04-08T15:52:52.307+0800 imported 0 documents
提示我逗号??一看我这个没问题,也是JSON格式呀,懵逼的一瞥。
{
"user_id": "脱敏",
"account": "脱敏",
"password": "脱敏",
"phone": "脱敏",
"lock_status": "脱敏"
},
{
"user_id": "脱敏脱敏",
"account": "脱敏",
"password": "脱敏",
"phone": "脱敏",
"lock_status": "脱敏"
}
然后我再 stackoverflow 看到可以使用 -vvvvv 确定报错的位置。
[root@iZm5ec7pkk6xphure3pgf5Z bin]# ./mongoimport -h localhost:9085 -c gm_users -d api --mode upsert --file gm_user1.json -vvvvv
2019-04-08T16:01:46.285+0800 using upsert fields: [_id]
2019-04-08T16:01:46.285+0800 using 4 decoding workers
2019-04-08T16:01:46.285+0800 using 1 insert workers
2019-04-08T16:01:46.285+0800 filesize: 72218 bytes
2019-04-08T16:01:46.285+0800 using fields:
2019-04-08T16:01:46.285+0800 will listen for SIGTERM, SIGINT, and SIGKILL
2019-04-08T16:01:46.288+0800 connected to: localhost:9085
2019-04-08T16:01:46.288+0800 ns: api.gm_users
2019-04-08T16:01:46.288+0800 connected to node type: standalone
2019-04-08T16:01:46.288+0800 standalone server: setting write concern w to 1
2019-04-08T16:01:46.288+0800 using write concern: w='1', j=false, fsync=false, wtimeout=0
2019-04-08T16:01:46.288+0800 standalone server: setting write concern w to 1
2019-04-08T16:01:46.288+0800 using write concern: w='1', j=false, fsync=false, wtimeout=0
2019-04-08T16:01:46.288+0800 Failed: error processing document #2: invalid character ',' looking for beginning of value
2019-04-08T16:01:46.288+0800 imported 0 documents
嗯,还是这个问题。而且我这个应该是第一个json就出问题了!
最后,找遍了百度,官方文档(可能是我遗漏了)没找到,最后的最后,忘记是在哪看到的了,就是因为这个 , (逗号)的问题,它喵的,有了它就会报错,然后用 UE 把这些 ,(逗号)删除了(我是因为数据量小才用的UE ,数据量大别用这玩意)
{
"user_id": "脱敏",
"account": "脱敏",
"password": "脱敏",
"phone": "脱敏",
"lock_status": "脱敏"
}, 《-------------------------------就是因为这个逗号
{
"user_id": "脱敏脱敏",
"account": "脱敏",
"password": "脱敏",
"phone": "脱敏",
"lock_status": "脱敏"
}
呐,变成这样子就欧拉!!
{
"user_id": "脱敏",
"account": "脱敏",
"password": "脱敏",
"phone": "脱敏",
"lock_status": "脱敏"
}
{
"user_id": "脱敏脱敏",
"account": "脱敏",
"password": "脱敏",
"phone": "脱敏",
"lock_status": "脱敏"
}
然后再使用导入脚本执行一下
[root@iZm5ec7pkk6xphure3pgf5Z bin]# ./mongoimport -h localhost:9085 -c gm_users -d api --mode upsert --file gm_user1.json
2019-04-08T16:15:31.715+0800 connected to: localhost:9085
2019-04-08T16:15:31.767+0800 imported 576 documents
欧拉,导出成功拉,它喵的。
附MongoDB官方文档地址:https://docs.mongodb.com/manual/reference/program/mongoimport/