Package for monitoring users' online status / presence?

sure, it (it = my code) works - but not very efficiently :wink:

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ā€¦ :slightly_smiling:

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 :slightly_smiling:.

1 Like

Yeah - Iā€™ll pull up some code now, so we can get to the bottom of this :smile:

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? :confused:

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.

2 Likes

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