Why mongodb giving exception “BSON representation of supplied JSON is too large”
Are you getting the exception “BSON representation of supplied JSON is too large” while importing JSON into mongodb via the mongoimport command in the mongoshell?
Is your JSON data formatted as one big array that looks like this …
1. Try Adding –jsonArray flag
If yes, then try adding the –jsonArray at the end of the mongoimport command like …
mongoimport -h dx3243.mongolab.com:1234 -d yourdb -c yourcollection -u username -p secretxxx --file data.json --jsonArray
You can learn more about the mongoimport flags here. The documentation says that the –jsonArray flag …
“Accept import of data expressed with multiple MongoDB documents within a single JSON array.”
2. Split the file
The documentation also says that the size of the file can be as large as 16MB (as of version 2.2). So check the size of your JSON file to see if it is larger than 16MB. If so, split the file up.
3. Reformat as the data
Alternatively, you can reformat your data to be as a series of object each object being on its own line without comma separation. It looks like…
While this technically is not JSON format. Mongodb accepts it. And it the format that is dumped out by mongoexport.