I am currently using nodejs and mongoose and trying to set my document to be removed after 30 minutes. But this happens faster than expected, about 2 to 3 minutes after saving to DB.
After searching, I found and tested this, but it made no difference
this is my schema code:
// require packages
const mongoose = require('mongoose')
const Schema = mongoose.Schema
// create users schema
const EmailSchema = new Schema({
email: {type: String, required: true},
code: {type: String, required: true},
reason: {type: Number, required: true},
reStatus: {type: Boolean, default: false},
createdAt: {type: Date, expires: 1800, default: Date.now}
});
module.exports = mongoose.model('Email', EmailSchema);
and this is how I save data :
new this.model.Emails({
email: email,
code: code,
reason: req.body.reason,
}).save(err => {
if (err) throw new Error(err);
return res.json({
massage: 'code saved successfuly',
success: true
})
});
The document is saved without any problems, but instead of 30 minutes later it is deleted after 2 to 3 minutes.