Help: Activity Log schema for different resource types


in my IoT application i want to make activity logs for some resources in my application
for example:
user A added a new device named XXX on 2022-01-20
user A deleted a device on 2022-01-21
an email was sent by the system to because of an XXX alarm on 2022-01-22

and so on…

the actor of the activity may be the user or the application itself

what are the common cases to design such schema

if you need more details, just ask

First I am not an expert,

but it would help to know what is the amount of those messages, and if you want them
to be kept in MongoDB or just log them somewhere?

I could advise you generally use triggers/change stream (only on replicaSet).
so whenever an operation is coming you could create an audit message by
the operation type: insert/ update / delete… and the value,
change stream supports for example update description and containing the entire document that has been changed.

this could lead to a more robust architecture in which you can send those messages to a queue,
which could be combined with several services publishing to the same queue also.

so your audit messages could be delivered from the trigger/change stream on the collection
and your “email was sent…” messages could be published from others.

of course that the consumer of this queue could create such a log as you wish.

hope it will give you some insights.