Best schema for user logs in analytics context

Hi guys! I have a question related to, which is the better schema based on this case:

  • Store the user id and timestamp when was assigned to call.

Is better to save assignment logs in a single or in multiple documents?

Multiple documents:

  "call": ObjectId,
  "user": ObjectId,
  "createdAt": ISODate

Single document:

 "users": [{ "user": ObjectId, "createdAt": ISODate }],
 "call": ObjectId

In the context of preferring an easy scheme to analyze assignments per user. To respond to question like:

How many calls were assigned yesterday?
Which users were assigned to X call?
Month, week, day, hour, with most than X assignments.
Total time in assignment for X call.


Hi @Matias_Lopez,

Welcome to MongoDB community!

The question is what are the most common application user queries and this should define the schema.

If your application need to present call details with participate details it make sense to store it in an array if the amount of participants is not large.

If I would go with the array approach I would do 2 mandatory things:

  1. Store the amount of participants in the root level and keep it updated as the array grows as well as the call time/duration in the main object.
    2.I would index users.user to use miltikey searches for user calls.

If there could be houndreds of participants per call I would not keep it in an array ,you can explore a hybrid solution using the Outlier pattern

I would recommend reading our schema antipattern article


1 Like

Thanks, @Pavel_Duchovny!! Yesterday I read that post and consistently bucket pattern is our case.

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