I'm trying to delete a product at a specific time how can I go about it,
expired_at doesn't work
Here my database
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const ProductSchema = new Schema(
{
category: {
type: Schema.Types.ObjectId,
ref: 'Category',
},
owner: {
type: Schema.Types.ObjectId,
ref: 'Owner',
},
title: String,
description: String,
photo: String,
price: Number,
stockQuantity: Number,
reviews: [{ type: Schema.Types.ObjectId, ref: 'Review' }],
// expireAt: { type: Date, default: Date.now, expires: "5m" }
},
{
toobject: { virtuals: true },
toJSON: { virtuals: true },
}
);
const Product = mongoose.model('Product', ProductSchema);
module.exports = Product;
Please how can I go about this
CodePudding user response:
try these
createdAt: {
type: Date,
default: Date.now,
expires: 30
}
create a new product after you've saved this so you'll get the time stamp on the product, this would delete the product in 30 seconds