Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected end of JSON input in MongoDB Compass

Tags:

I want to import data of type JSON in MongoDB compass, the import function gives this error " unexpected end of JSON input "

enter image description here

there is a some of my JSON file

[    {       "id":4,       "user":"[email protected]",       "date1":"2019-03-01",       "date2":"2019-04-01",       "statut":"Good",       "guest_number":4    } ] 
like image 263
OAH Avatar asked May 15 '19 13:05

OAH


Video Answer


2 Answers

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 
like image 165
OAH Avatar answered Oct 16 '22 17:10

OAH


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.

like image 33
Schwarz54 Avatar answered Oct 16 '22 16:10

Schwarz54