Unexpected end of JSON input in MongoDB Compass

I had this issue 6 month ago, the solution is write all JSON in one line. [{"id":4,"user":"[email protected]","date1":"2019-03-01","date2":"2019-04-01","statut":"Good","guest_number":4}]

MongoDB Compass will told you:

Import success!

But definitely the document will not appear in your collection, so better use Robo3T if you gonna insert json. Then you can use again Compass like I do. It is weird, yes, but I didnt found other solution yet.

[UPDATE]

I achieve import data with Compass, but I achieve exporting first a document from Compass to see how it write the json.

{"_id":{"$oid":"5e4cf105c9ba1a21143d04a2"},"tPreguntas":["Pregunta 1","Pregunta 2","Pregunta 3","Pregunta 4","Pregunta 5"],"tCategorias":[],"tPublico":true,"tFechaCreacion":{"$date":{"$numberLong":"1582100741716"}},"tCodigo":"test1","tTitulo":"Test 1","tDescripcion":"Test de muestreo número uno para comprobar.","tCreadoPor":"[email protected]"}

It look to different to the json online I have post in my first post. (look that objectId "$oid" for example). So if you follow that pattern Compass will import you fine.


the solution is to write all JSON in one line, but if we have a big doc !! I just found a solution that I can import data with this command in terminal :

mongoimport --jsonArray --db YourDatabase --collection YourCollection --file Yourfile.json

Tags:

Json

Mongodb