But when I insert an object to the document from nodeJs I need to calculate the size of the document, just to make sure it does not exceed the 16MB document limit. If it does, then I wanted to create another document and keep inserting multiple objects into the newly created document. So every time I do not want to run aggregation on the database instance before inserting a new object into the document.
I tried using the BSON library which can calculate the BSON size of the JSON object before inserting it into the document. But it seems it does not calculate BSON size correctly.
Can someone please suggest to me the correct way to calculate the BSON size of the object which I want to insert into the document?
I tried the same way. But the size of all objects present in one document does not match with size which I calculate from the mongo command line interface using $bsonSize.
Thank you for your help. But now I am using bson from mongo. It works with the same approach. But the library of bson which I installed using ‘npm install bson’ does not provide me correct object size.