MongoExport 导出有效的 JSON。您的 Java 应该将每一行而不是整个文件解析为 JSON 对象。
如果要将整个导出文件视为 JSON 对象,请使用该选项--jsonArray
--jsonArray
output to a json array rather than one
object per line
例子:
mongoexport --db test -c x
connected to: 127.0.0.1
{ "_id" : "54c8f3fb5e24e03c473243c4", "username" : "Aman", "password" : "yesboss" }
{ "_id" : "54c901c1953b434dabadbabf", "username" : "AMAN2" }
exported 2 records
mongoexport --db test -c x --jsonArray
connected to: 127.0.0.1
[{ "_id" : "54c8f3fb5e24e03c473243c4", "username" : "Aman", "password" : "yesboss" },{ "_id" : "54c901c1953b434dabadbabf", "username" : "AMAN2" }]
exported 2 records