add_index_for_sync_state.js 621 B

123456789101112131415161718192021
  1. /* eslint-env mongo */
  2. // add a TTL index to expire entries for completed resyncs in the
  3. // projectHistorySyncState collection. The entries should only be expired if
  4. // resyncProjectStructure is false and resyncDocContents is a zero-length array.
  5. const now = Date.now()
  6. const inTheFuture = now + 24 * 3600 * 1000
  7. db.projectHistorySyncState.ensureIndex(
  8. { expiresAt: 1 },
  9. { expireAfterSeconds: 0, background: true }
  10. )
  11. db.projectHistorySyncState.updateMany(
  12. {
  13. resyncProjectStructure: false,
  14. resyncDocContents: [],
  15. expiresAt: { $exists: false },
  16. },
  17. { $set: { expiresAt: new Date(inTheFuture) } }
  18. )