does anyone have experience with ttl for mongoose
I am trying to set it for my schema to delete documents if the user is not premium at certain seconds, using the partialFilterExpression
but the document is being deleted
regardless the state of the user
this is my schema
const postSchema = new mongoose.Schema(
{
title: { type: String },
description: { type: String },
image: { type: String },
price: { type: String },
location: { type: String },
image: { type: Array },
author: {
type: String,
ref: 'User'
},
authorPremium: {
type: Boolean,
default: false,
index:true
},
reported: {
type: Boolean,
default: false
},
reportClear: {
type: Boolean,
default: false
}
},
{
timestamps: true
}
);
// users who are premium will keep post for 120 days
// postSchema.index({createdAt: 1},{expireAfterSeconds: 360,partialFilterExpression : {authorPremium: true}});
// users who are not premium will have posts deleted after 20 seconds
postSchema.index({ createdAt: 1 }, { expireAfterSeconds: 20, partialFilterExpression: { authorPremium: false } });
module.exports = mongoose.model('Post', postSchema);