TTL Indexing and Subset Collection

Hey Community, I have a few questions about TTL indexing in order to achieve the following goals:

  • Delete an event document from a current events collection (let’s say a concert) when the event has finished.
  • Save the deleted event in a separate expired events collection for future analysis.
  • Delete all occurrences of the deleted event from user arrays that store a subset version of it (users are able to view a few item fields in the subset that rarely/never change such as event name, event date, etc.). For clarity, these arrays would exist in a separate users collection.

Rationale / Comments:

  • My application only presents current events to users but our team will want to be able to run queries on past events for analysis. The response time of these queries is much more flexible (i.e., they can be run overnight worst case scenario) since its just analysis vs. realtime user experience.
  • The deletion of the event does not need to be immediate but should be close to when it expires (said differently, I would rather the application perform better vs running functions constantly that would lead to performance issues, if any)
  • I am using Realm and understand (with limited knowledge even after reading docs and threads) that I need to create a trigger that will call a specific function. Instead, I added a TTL index in Compass that will call an expireAtSeconds of 0. I guess I am trying to use Realm / understand if there is any difference using Compass for this

Current Procedure / Thought Process:

  • TTL Index works incredibly well to delete an event through Compass, no need to make any changes inside Realm
  • Instead of saving the event I am deleting to a separate collection, I currently am saving this event to a separate collection when it is created and finalized (e.g., I won’t save this event document to the second collection until user posts the event publicly or similar). This way, my TTL index will delete the current event but another collection will keep the same event data for future analysis in the second collection.
  • Unknown - What is the most performant way to remove all occurrences of the event from subset arrays. In my example above I mentioned that users will have a subset of current events with event name and 1-2 other fields but in reality this subset that rarely changes may exist in other collections and arrays as well. Similar to the deletion of the current event, this does not need to happen instantly. I do not intend to save any of this subset data either.

Cheers! And as always, I am open to any suggestions or insight!