Skip to content

Commit a67c70a

Browse files
committed
💥 Change deleted from string to Date
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 } }) ```
1 parent 3b121da commit a67c70a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

‎mongodb-queue.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export type BaseMessage<T = any> = {
4848
export type Message<T = any> = BaseMessage<T> & {
4949
ack: string;
5050
tries: number;
51-
deleted?: string;
51+
deleted?: Date;
5252
};
5353

5454
export type ExternalMessage<T = any> = {
@@ -206,7 +206,7 @@ export class MongoDBQueue<T = any> {
206206
};
207207
const update: UpdateFilter<Message<T>> = {
208208
$set: {
209-
deleted: now(),
209+
deleted: new Date(),
210210
},
211211
$unset: {
212212
visible: 1,

0 commit comments

Comments
 (0)