Here I record the issues found during the development using MongoDB and Mongoose ORM.
Document Size Limit
According to the official doc, each document in MongoDB should not exceed 16 megabytes. For most non-plain-file data, this limit is high enough that it does not impose any limit on the development. However, in case some documents are expected to exceed this limit, some safety measures should be taken.
The most intuitive and simple solution will be to split the data into multiple documents. For the documents starting small the implementation of the solution is quite simple:
As shown above, when appending new data to the document, the first try assumes that the operation can simply succeed. Once error code 17419 or 10334 is thrown, the server rejects the operation as the resulting document's size will exceed the limit. Now new document must be created to store the new data.
This solution does require some handling on the application layer, like merging documents on query. But the overhead of data insertion is kept minimal.