Delete MongoDB document at specific time

后端 未结 4 1216
别那么骄傲
别那么骄傲 2020-12-09 12:41

I am looking into deleting a document at a specific time.

const TestSchema = new Schema({
 expire_at: {
 type: Date,
 },
}, {
 timestamps: true,
});
TestSche         


        
4条回答
  •  鱼传尺愫
    2020-12-09 13:10

    This will delete the document in two hours:

    const TestSchema = new Schema({
        expire_at: {type: Date, default: Date.now, expires: 7200} 
    })
    
    //expired in 2 hours
    

提交回复
热议问题