Надеюсь кому-то поможет:
// Shema
import { Schema, model } from "mongoose";
const TestSchema = new Schema({
walletAddress: {
type: String,
},
expireAt: {
type: Date,
default: Date.now,
required: true
}
},)
TestSchema.index( { "expireAt": 1 }, { expireAfterSeconds: 0 } );
export default model('TestModel', TestSchema)
// Controller
class TestController {
async add(req, res) {
try {
const { walletAddress, time } = req.body;
const expireAt = new Date();
expireAt.setHours(expireAt.getHours() + Number(time));
const newWallet = await testSchema.create({
walletAddress,
expireAt
});
await newWallet.save()
return res.json({newWallet})
} catch(err) {
console.log(err)
}
}
}
export default new TestController();