From a17040f00f69ac01c54f9b12721ef179b75fc3a0 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 11 Aug 2016 12:03:50 +0100 Subject: [PATCH] Add commentary on ttl index --- services/notifications/README.md | 10 ++++++++++ services/notifications/app/coffee/Notifications.coffee | 2 ++ 2 files changed, 12 insertions(+) diff --git a/services/notifications/README.md b/services/notifications/README.md index 02e1a15e78..9db344dae4 100644 --- a/services/notifications/README.md +++ b/services/notifications/README.md @@ -2,3 +2,13 @@ notifications-sharelatex =============== An API for managing user notifications in ShareLaTeX + + +database indexes +================ + +For notification expiry to work, a ttl index on `notifications.expiresFrom` must be created: + +```javascript +db.notifications.createIndex({expiresFrom: 1}, {expireAfterSeconds: (60*60*24*30)}) +``` diff --git a/services/notifications/app/coffee/Notifications.coffee b/services/notifications/app/coffee/Notifications.coffee index 4238ae37e9..1f0e1b8237 100644 --- a/services/notifications/app/coffee/Notifications.coffee +++ b/services/notifications/app/coffee/Notifications.coffee @@ -29,6 +29,8 @@ module.exports = templateKey: notification.templateKey expires: notification.expires || false # ttl index on `expiresFrom` field + # in Mongo, TTL indexes only work on date fields, + # and ignore the document when that field is missing if doc.expires doc.expiresFrom = new Date() db.notifications.insert(doc, callback)