navid
4 سال پیش توسط navid مطرح شد
0 پاسخ

نوشتن expire در mongoose

سلام دوستان این مدل منه میخوام expires بشه
تو stackoverflow هم گشتم ولی هر روشی رو تست کردم بازم حذف نمیشه فیلدم از دیتابیس!
(1)

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const timestamps = require('mongoose-timestamp');

const testSchema = new Schema({
name : { type : String , createdAt: { type: Date, expires: '1m', default: Date.now }}

});
// testSchema.index({createdAt: 1},{expireAfterSeconds: 3600})

testSchema.plugin(timestamps);
module.exports = mongoose.model('Test' , testSchema , 'test');

(2)

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const timestamps = require('mongoose-timestamp');

const testSchema = new Schema({
name : { type : String , required : true}

});
testSchema.index({createdAt: 1},{expireAfterSeconds: 3600})
testSchema.plugin(timestamps);

module.exports = mongoose.model('Test' , testSchema , 'test');

(3)

> const mongoose = require('mongoose'); const Schema = mongoose.Schema;
> const timestamps = require('mongoose-timestamp');
> 
> const testSchema = new Schema({ name : { type : String , required :
> true , index: { expires: 'expires: 3600' }}
> 
> });
> 
> testSchema.plugin(timestamps);
> 
> module.exports = mongoose.model('Test' , testSchema , 'test');

این سه روش رو تست کردم اما جواب نمیده!


ثبت پرسش جدید

به همدیگه کمک کنیم

به navid کمک کنید تا مشکل خودش را حل کند؛ این‌طور می‌توانیم با هم پیشرفت کنیم.

برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام