0

I have a Notification Schema which includes an array of recipients. If a Notification documents' recipients array becomes empty, then I want it to be automatically deleted.

Is this possible? Thanks

bloppit
  • 621
  • 8
  • 22

1 Answers1

1

This is not possible within Mongoose. I would suggest when you remove the final recipient, check if the array is empty then delete the document. This might be a useful stack overflow post if you want to delete all documents where the recipient array is empty: Find MongoDB records where array field is not empty

Community
  • 1
  • 1
sstrickland
  • 60
  • 1
  • 2
  • 5