Handling Custom Log Data in MongoDB

Hello everyone.

I would like to know some of the best practices for storing custom log data in mongodb.

This is my requirement:

I want to be able to log user’s activities in my client-side application. e.g) which page the person entered and how long the person stayed in the page and so forth.

My solution:

Create a document that comprises detailed activities(log data) per each user once a day.

Possible Problem in the future:

This seems like not a scalable solution. If the number of users grew, so is a number documents that track users’ activities.

If there are more experienced people out there, what are your take on this type of situation? I would love to have some discussions.

Thanks.

Welcome to the MongoDB Community @Suk_Yu!

It sounds like you are describing a Web Analytics solution that could either be part of your custom application code or use a third party service like Google Analytics.

If you would like to track daily user activity on a detailed level, it is expected that the number of documents will grow with your user base.

Perhaps you would want to roll up some of the user log activities into summary documents using Time Series Collections or Materialised Views. If you are using MongoDB Atlas, you can also take advantage of features like Online Archive to move infrequently accessed data to a read-only archive using cloud object storage for cost savings.

If you don’t have custom requirements and the analytics are for your own purposes rather than displaying to end users, I would be inclined to use an existing third party web analytics solution.

Regards,
Stennie

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.