partial filter expression is deleting post regardless of filter

55 views
Skip to first unread message

xxx

unread,
Feb 24, 2020, 11:25:02 PM2/24/20
to Mongoose Node.JS ODM
Enter code here...

does anyone have experience with ttl for mongoose
8:20 PM
I am trying to set it for my schema to delete documents if the user is not premium at certain seconds, using the partialFilterExpression
8:20 PM
but the document is being deleted
8:20 PM
regardless the state of the user
8:21 PM
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);


Reply all
Reply to author
Forward
0 new messages