How to Import JSON into MongoDB using NoSQLBooster
Adam C. |

Different from MySQL, it's pretty hard to find a FREE and full function GUI tool for MongoDB. We have tried three FREE popular MongoDB GUI. 

  1. Robo 3T - very limited feature, and cannot even import
  2. MongoDB Compass  -  modern feel UI, but lack of some important features, for example, renaming a collection
  3. NoSQLBooster - classic UI (okay for me), and has most features we need except missing export

In case you are looking for a FREE MongoDB GUI, here is a comparison of free vs paid of NoSQLBooster: https://nosqlbooster.com/compareEditions

Photo by Jan Antonin Kolar on Unsplash

We have been used to import CSV data into a MongoDB collection for a while, which works very well. But we got the error when importing JSON data. That might sound very weird, doesn't it? It ends up because we did not provide the "correct" JSON format. Let's see what JSON format to make NoSQLBooster happy.

Let's first look at the JSON data as below:

[{
		"done": false,
		"task": "write about nosqlbooster"
	},
	{
		"done": false,
		"task": "look for the best mongodb gui!"
	}
]

We used https://jsonlint.com/ to make sure it's valid, and then we tried to import it into a collection.

Import JSON Data into MongoDB

Right click on a collection → Click on ‘Import Collection’ → Click on 'Mongoimport (JSON and CSV), and the the window open to allow us to choose the JSON file, but after we chose the validated JSON file, the popup window shown with the error message:

The specified file “xxx” is not valid mongoexport JSON file

Cannot Import JSON using NoSQLBooster

Believe or not we could not find the answer by Googling this issue, but we found that we can import the JSON data if it contains only one record like:

{
	"done": false,
	"task": "write about nosqlbooster"
}

NoSQLBooster does not allow import multiple records? That does not sound right, we can always import CSV file without any issues. Finally we figured out that it does not like valid JSON data. Instead, we have to provide an invalid JSON data, like below:

{"done": false,"task": "write about nosqlbooster"}
{"done": false,"task": "look for the best mongodb gui!"}

You're right, no Array (i.e., []), no commas. Just need to write your records one by one.

That's it. Hope you find this helps until NoSQLBooster fixes this issue. :-)