I am using MongoDB with Next.js. What I am trying to do is, I try to add as many sub-documents as possible to so that I can reduce the lookup time when doing a find
operation. However, the maximum document is 16Mb, I will create a new document and add the sub-document to a new document if the new size will exceed 16MB.
Is there a way to check the size of the document before the insertion? For example, the current size of the document is 15mb, and I have a 2mb sub-document. I see that 15+2==17 which is greater than 16. So, we will create a new document for this new sub-document.