Skip to content

Conversation

@alecgibson
Copy link
Collaborator

@alecgibson alecgibson commented Feb 10, 2025

This is a BREAKING change that will change the deleted field from a string to a Date, which will let us set up a TTL index on it.

Although this change is technically breaking, it should be deployable with no impact on Production, since we only ever query deleted using the $exists operator.

In order to leverage the TTL index, we'll need to:

  1. Deploy this change
  2. Migrate all existing deleted fields to Date:
    db.collection.update(
      {deleted: {$type: "string"}},
      [{$set: {deleted: {$toDate: "$deleted"}}}]
    )
  3. Change the existing deleted index to TTL:
    db.runCommand({
      collMod: '...',
      index: {
        name: 'deleted_1',
        expireAfterSeconds: 2592000, // ~ 1 month
      }
    })

This is a **BREAKING** change that will change the `deleted` field from
a `string` to a `Date`, which will let us set up a TTL index on it.

Although this change is technically breaking, it should be deployable
with no impact on Production, since we only ever query `deleted` using
the `$exists` operator.

In order to leverage the TTL index, we'll need to:

 1. Deploy this change
 2. Migrate all existing `deleted` fields to `Date`:
    ```js
    db.collection.update(
      {deleted: {$type: "string"}},
      [{$set: {deleted: {$toDate: "$deleted"}}}]
    )
    ```
 3. Change the existing `deleted` index to TTL:
    ```js
    db.runCommand({
      collMod: '...',
      index: {
        name: 'deleted_1',
        expireAfterSeconds: 2592000, // ~ 1 month
      }
    })
    ```
@alecgibson alecgibson merged commit d4da1aa into main Feb 10, 2025
2 checks passed
@alecgibson alecgibson deleted the date-deleted branch February 10, 2025 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants