Hi i came across one concept called as ttl in mongodb and tried the same in a insert operation using mongoose.Below is the code
mongoose = require('mongoose');
var Schema = mongoose.Schema;
var META_CTS_DB = mongoose.createConnection('mongodb://localhost/META');
var ttl= require('mongoose-ttl');
var date1=new Date();
var ServiceSchema = new Schema({
_id:String,
CURDATE:{type:Date,index:true},
SERVICE_PROTOCOL:String,
});
ServiceSchema.plugin(ttl, { ttl:5000 });
var MasterDBdata = META.model('ServiceSchema',ServiceSchema,'API_KEY_91994094177912_SERVICE_ID_0008_SERVICE_CONFIG');
var item = new MasterDBdata({'_id':'SERVICE_ID_0006','CURDATE':date1,'SERVICE_PROTOCOL':'Nil'});
item.save();
The ttl worked fine for this and the collection did get deleted.But when i performed the same for a update function as below
MasterDBdata.update({'_id':'SERVICE_ID_0006'},{'CURDATE':date1,'SERVICE_PROTOCOL':'hhl'},{upsert:true},function (err){
if (err) return handleError(err);
console.log('\n data stored in Database...')});
The ttl function didnt seem to work properly.Any idea regarding the behaviour of ttl and its performance on these functions will be really helpful.Thanks in advance
The mongoose-ttl plug-in uses its own hidden __ttl field to track a document's expiration time, so updating your own CURDATE field isn't going to have any effect.
If you're on MongoDB 2.2 you should be using the native support for TTL collections instead of the plug-in, defining CURDATE as the expires key field as discussed in your previous question here.