0

I want to delete a particular task document automatically. createdAt: {type: Date} => it will take future date and time, and duration:{type: String} => it will take time in hours. whenever the future time arrives from that time to next how much duration we insert, after completion of duration the task document will delete


const mongoose = require('mongoose')
const TaskSchema = new mongoose.Schema({
    taskName: { type: String, required: true },
    description: { type: String },
    creator: { type: String },
    duration: { type: String },
    createdAt: {type: Date}
})

const Tasks = mongoose.model('Task', TaskSchema)

module.exports = Tasks```


**Please help how to approach this task**
Jatin Mehrotra
  • 9,286
  • 4
  • 28
  • 67

1 Answers1

0

try this

  const TestSchema = new Schema({
        expire_at: {type: Date, default: Date.now, expires: "your desired value"} 
    })

this is the solution you are looking for here

Jatin Mehrotra
  • 9,286
  • 4
  • 28
  • 67
  • once a data is created with a duration, it should be automatically deleted after the assigned duration. That means if I create a task called "Interview Assignment" with duration set to 30 mins at 1:00pm on 1 January, the record in the database will be automatically removed at 1:30pm on 1st January. – Siddu Siddartha Sep 08 '20 at 05:59