I'm trying TLL in MongoDB schema. I know I can hard code a TLL index in the schema, for example, 60. And this object will get removed from the database after 60 seconds. But I'm thinking about a scenario in that I let the user decide how long an object created by him will last in the database. For example, the user is posting a question. And the user wants to decide how long this question will be live on the website, for example, 15 days or 30 days or whatever he wants. So, I cannot hard code a TLL index. Can someone tell me if there's a way I can use a variable for TLL or if there's a better to do this task? Thank you. Below is the code for the schema I have for now.
const questionSchema = new mongoose.Schema({
question: {
type: String,
}
}, {timestamps: true});
ratingSchema.index({createdAt: 1},{expireAfterSeconds: 60});