Watch keynotes and sessions from MongoDB.live, our virtual developer conference.

Getting the previous data in a database trigger

Is it possible to get the previous data in a database update trigger event? I have been unable to find anything in the docs that suggests you can.

My scenario is this: I have two collections with a many-to-many relationship: Users and Groups. I’d like to setup a trigger that, when a group has its “members” field updated (an array of ids), it updates each user’s “groups” field to contain that group id.

This is fine for adding members to a group but not removing. If I only receive the current value of the “members” field in the trigger, I’m not able to update the removed users.