5

Is it possible to automatically set a a modified date when performing an update? Or does this have to be done programmatically?

Mark Walsh
  • 3,241
  • 1
  • 24
  • 46
  • I see triggers [here](https://docs.mongodb.com/stitch/mongodb/triggers/) but looks like specific to stitch – titogeo Sep 03 '18 at 12:32
  • https://stackoverflow.com/questions/9691316/how-to-listen-for-changes-to-a-mongodb-collection – titogeo Sep 03 '18 at 12:34
  • @titogeo - This may be workable but wouldn't this mean I'd effectively have to update the documents twice? Once for the initial update and again with the timestamp afterwards. – Mark Walsh Sep 03 '18 at 12:35
  • Yes, Or else use some application frameworks ( like for Java there is spring-data-mongo). This will update records on the fly (before actual write to DB) without needing to update twice. And I think its same for all databases. – titogeo Sep 03 '18 at 12:39
  • @MarkWalsh I’d say that heavily depends on your data model. `db.yourcoll.update(foo,{bar:baz,updated:now})` should work just fine. – Markus W Mahlberg Sep 03 '18 at 14:56
  • That would require me to modify every single one of my update statements. I was looking for a way to track this automatically. – Mark Walsh Sep 04 '18 at 07:42

0 Answers0