I would like to set a session bound value that\'s synced between client and server in Meteor. I\'m thinking that should be done in a Collection, since Session isn\'t synced betw
I would recommend indexing the particular field in the collection with a TTL parameter, this will ensure that documents expire after a specified time.
Do it from the Mongo shell like so:
db.myCollection.ensureIndex( { "fieldName": 1 }, { expireAfterSeconds: 3600 } )
You could remove the records for a collection after a certain amount of time.
Server side code:
//Run every minute
Meteor.setInterval(function() {
MyCollection.remove({expires: { $gte: new Date() }});
}, 60000);
When you insert it you can set an expiry:
Server side code:
MyCollection.deny({
insert: function(userId, doc) {
//Set expiry to 24 hours from now
doc.expires = new Date( new Date().getTime() + (36000000*24) );
}
});
The deny method adds the expiry time on the server, even if you add a document from the client. This way you can ensure documents expire regardless of the time on the client, which can often be incorrect.
Then you can insert the document on the client side
Client side
MyCollection.insert({ base64data: xxxxxx });
Also yes you're right, Session
does not sync with the server.