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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -