navid
6 سال پیش توسط 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');

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