I'm trying to figure out, how to calculate size before storing some data to MongoDB. Since I wrote a script that parses data, combining them in a single document and trying to do instance.save()
.
So far I am getting an error such as:
BSONObj size: 17102819 (0x104F7E3) is invalid. Size must be between 0 and 16793600(16MB)
I don't want to use gridFS, because it is architecture-dependent and the project is big enough to use it, so far I decided to skip such documents that have a greater size than required.
I found the article about: How to calculate existing document BSONSize
Link to the article: https://betterprogramming.pub/how-to-calculate-mongodb-document-size-in-node-js-f463b8457f27
But, I need to figure out, how to calculate it before storing it in the database