Partial filter expression is deleting post regardless of filter

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);

Hey @_3x

I think (could be wrong) by setting index here.

authorPremium: {
 type: Boolean,
 default: false,
 index:true
 },

and the partial at the end is making 2 indexes. Maybe only do the one at the end with the partial filter.

I found a few stackover flows (including yours) about this.


Just want to make sure you are on a version of mongodb that supports partial filters. As Other than that I am not sure why the above is not working as expected.