add_index_for_sync_state.js 597 B

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