Based on the answer in this post I have created the following document schema, which sets every new document created to expire 24 hours after its creation :
var mongoose = require('./node_modules/mongoose');
mongoose.connect(mongodburi, {
server : {
socketOptions : {
keepAlive: 1
}
},
replset : {
socketOptions : {
keepAlive: 1
}
}
});
var sessionSchema = mongoose.Schema({
uid: {
type: String,
required: true,
unique: true
},
token: {
type: String,
required: false,
unique: true
},
createdAt: {
type: Date,
default: Date.now,
expires: 24*60*60
}
});
var Session = mongoose.model('Session', sessionSchema);
I want to be able to reset the expiration of a document for another 24 hours. Is this the way to do it (?) :
Session.update({uid: someUID}, {createdAt: Date.now}, null, function (err, numOfSessionsUpdated)
{
if (numOfSessionsUpdated > 0)
{
console.log('session expiration has been postponed for another 24 hours');
}
});