sure, it (it = my code) works - but not very efficiently
no, I couldnāt make TTL work from within Meteorā¦
sure, it (it = my code) works - but not very efficiently
no, I couldnāt make TTL work from within Meteorā¦
What do you mean by that exactly? Iāve used that technique successfully before.
well, I think polling the DB is unnecessary, and that I can get the same result with, for example, TTL in Mongo. I imagine that would be more efficient.
Awesome that youāve done this before - do you have any advice on improving my code?
Iām not sure if thereās other areaās of improvement - Havenāt put much thought into it yet, and havenāt tested how performant it is either, soā¦
Ah - I thought you were saying that using MongoDBās TTL didnāt work from Meteor.
wauw, I completely misunderstood:
I couldnāt make it work last night - I did it like this:
example._ensureIndex({expireAt:1},{expireAfterSeconds:0})
That value of 0 for expireAfterSeconds is for use when expiring at a particular clock time (which I havenāt tried). Using a non-zero value (relative time) works fine though - so you may still be right .
Yeah - Iāll pull up some code now, so we can get to the bottom of this
const ttl = new Mongo.Collection('ttl')
ttl._ensureIndex({expireAt:1}, {expireAfterSeconds:5})
Meteor.setInterval(() => {
ttl.insert({expireAt:new Date()})
}, 10000)
The above doesnāt work
Iāll try and hack at it some more with different settingsā¦
Well, Iāve just tried my own experiment with values of 0 and non-0 and both work fine!
so if you copy/paste my code it works for you, or did you do something differently?
Different.
So, I added this in a server/
folder (my Coll = new Mongo.Collection('coll');
is in a lib/
folder):
Meteor.startup(function() {
if (Coll.find().count() === 0) {
Coll._ensureIndex({expireAt:1},{expireAfterSeconds:0});
const now = new Date();
const later = new Date(now.valueOf() + 60000);
Coll.insert({name:'bob', createdAt:now, expireAt:later});
}
});
and used meteor mongo
to watch the collection:
db.coll.find().pretty()
(yes, I kept clicking on that!).
Sure enough, at the appointed time the document had gone. Similarly for a non-zero value.
In recent times I am testing this package and I have to say that it is really well done!
for horizontal scaling the author advise to use it:
meteor-multiple-instances-status