javascript - Mongoose conditional TTL for document -
is there way set expiresat
index documents, depending on current document state?
yes, there is. need set both partialfilterexpression , expiresat indexes. works @ mongodb 3.2+
code below remove document after 24h if payed
property equal false
:
let billingschema = new mongoose.schema({ _id:type:number, summ:{ type:number, required:true }, description:string, payed:{ type:boolean, default:false, index:true }, ownerid:{ type:mongoose.schema.types.objectid, ref:'user', index:true } },{timestamps: true,_id: false}); billingschema.index({createdat: 1},{expireafterseconds: 24*60*60,partialfilterexpression : {payed: false}});
Comments
Post a Comment