I set expiry time to 24 hours, but the documents expire after around 5-10 minutes (I haven't timed it exactly). What am I doing wrong? My schema:
const collectionSchema = new mongoose.Schema({
userId: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
},
name: {
type: String,
maxLength: 30,
required: true
},
entries: [{ type: mongoose.Schema.Types.ObjectId, ref: "Entry" }],
expireAt: { type: Date, expires: 60 * 60 * 24 }
});
In the post route, I conditionally set the date so that inlogged clients get data persistence.
router.post("/", auth, async (req, res) => {
let date = null;
if (!req.user) {
date = new Date();
}
try {
const collection = {
userId: req.body.userId,
name: req.body.name,
expireAt: date
};
const newCollection = await Collection.create(collection);
res.send(newCollection);
} catch (error) {
res.send(error.message);
}
});
I thought I had a time-zone problem, but when I check the time stamp in MongoDB compass, it matches my time-zone. What am I doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…