title: How to effectively manage a LastUpdated field with MongoDB on .NET?
body: <p>I have a MongoDB database and I am making changes to it using the <code>MongoDB.Driver</code> NuGet package. I have a <code>User</code> collection and this user collection has a <code>LastUpdated</code> field. How do I effectively update this field whenever a user's other fields change without changing all update calls in my code?</p>
  <p>I know how to do this with EF Core. You need to override the <code>SaveChanges</code> and <code>SaveChangesAsync</code>  methods in the <code>DbContext</code> class and update the <code>LastUpdated</code> field of all entities marked as <code>EntityState.Modified</code>. I need to do this with MongoDB.</p>
  <p><a href="https://github.com/Meteor-Community-Packages/meteor-collection-hooks#beforeinsertuserid-doc" rel="nofollow noreferrer">This hook</a> does it with JS but I need it in .NET</p>