How to get user information of the document that has been inserted

Hi Team,

How can I get the details of the user that has performed DML operations like insert/delete/update to a collection?

The document in the oplog/ChangeStream doesn’t have any information on the user that has performed the operation.

I see db.getUsers() or db.runCommand( { usersInfo: 1 } ) to fetch the user details but not sure how to associate these user details with the document that has been inserted.

Any help on this?

Hi @Sabareesh_Babu

I think you’re looking for Auditing. However this feature is part of the MongoDB Enterprise Server, which requires an Enterprise Advanced subscription if you’re looking for an on-prem deployment of this feature.

Alternatively I believe you can do the same using Atlas M10+ deployments (i.e. not available for free & shared tier clusters):

(Yet) another idea is to create an API layer in front of the database server. This custom layer can then log anything you need.

Best regards