If we follow the first approach we don't know how to stop storing activity logs when the document is filled with 1k logs.
If we follow the second approach, while the client is reading the activity logs, it needs to scan more number of documents (every doc creates index which we don't need), so it may affect the storage and reading performance.
Hi,
Schema design in MongoDB is highly dependent on your use case, goals, and data access pattern of your application. Factors like how the data is generated and accessed should determine your schema design. If you want reads to be faster then the schema should align with the way the reads would be performed.
If We follow the first approach we don’t know how to stop storing activity logs when the document is filled with 1k logs.
Could you elaborate on the significance of the 1KB number? My understanding is that you want to “buffer” your logs until their total size reaches 1KB, at which point you write them as a single document (instead of writing the individual log entries). In this case, the logic must be coded in your application.
Whenever I am storing the each activity log as one document, It will create default “_id” which is indexed by default
Remember that you can choose the value of _id when inserting documents (as long as it’s unique), if you can use it for your queries as indexes are essential to achieve fast reads. If you don’t provide an _id field, a default _id will be provided for you.
You can find a lot of useful information in MongoDB Use Cases and in particular there is a Storing Log Data Use Case.
Regards,
Amar