I have a schema where I expire the document in 24 hours.
let mySchema = new Schema({
name: String,
createdAt: {type: Date, default: Date.now },
expire_at: {type: Date, default: Date.now, expires: 86400},
});
However, on some occasions I do not want to expire the document and then do myDocument.expire_at = null;
This seems to work and the document seems to not expire. However, are there better practices for achieving this or any problems that might occur if the document expiry is cancelled in this way?
Setting a field that has an ttl index on it to NULL
to not have it expire is documented and thus a valid way to do it. You could also remove the entire field rather than setting it to NULL
. (I'd prefer to keep the value; that way it's not ambiguous if the value is missing on purpose or not.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With