Locking Documents In Mongo

Hi @Jason_Widener,

We can only offer a TTL partial index on status : “processing” with 15 min time to live however, it will only remove the document.

Then you can consider listen to those deletes via a changestream or an Atlas trigger (if this is running on MongoDB Atlas cluster) and recreate the record.

However, this might be challenging and not really error proof.

I will suggest 2 approaches:

  1. Have a timeout in your code that after the allowed timeout will throw an error and in the catch block will update the status back to “pending”.
  2. Have a logic to pull the data of running processes for more than 15min and automatically change their statuses.

Best regards,
Pavel

1 Like