<NME> onlineusers_private.js
<BEF> import { Meteor } from 'meteor/meteor';
import { OnlineUsersSchema } from './onlineusers.schema';

if (Meteor.isServer) {
    Meteor.publish('onlineUsersForRoute', function (route) {
    Meteor.publish('onlineUsersForRoute', function (route) {
        if (route) {
            return OnlineUsersSchema.find({activeRoute: route});
        }
        return OnlineUsersSchema.find();
    });
}

const checkRouteParamAndAuthorization = (route, userId) => {
    check(route, String);
    if (!userId) {
        throw new Meteor.Error('not-authorized');
    }
};

Meteor.methods({
    'onlineUsers.enterRoute'(route) {
        const userId = Meteor.userId();
            activeRoute:route,
            updatedAt: new Date()
        });
    },
    'onlineUsers.leaveRoute'(route) {
        const userId = Meteor.userId();
    },
    'onlineUsers.leaveRoute'(route) {
        const userId = Meteor.userId();
        checkRouteParamAndAuthorization(route, userId);
        OnlineUsersSchema.remove({userId: userId, activeRoute:route});
    }
});
<MSG> #16: Remove outdated entries from onlineusers collection

<DFF> @@ -1,5 +1,6 @@
 import { Meteor } from 'meteor/meteor';
 import { OnlineUsersSchema } from './onlineusers.schema';
+import moment from 'moment/moment';
 
 if (Meteor.isServer) {
     Meteor.publish('onlineUsersForRoute', function (route) {
@@ -24,6 +25,10 @@ Meteor.methods({
             activeRoute:route,
             updatedAt: new Date()
         });
+
+        // remove outdated entries
+        const fiveMinAgo = moment().add(-1,'minutes').toDate();
+        OnlineUsersSchema.remove({updatedAt: {"$lt" : fiveMinAgo}});
     },
     'onlineUsers.leaveRoute'(route) {
         const userId = Meteor.userId();

{'addition_count': 5, 'commit_subject': '#16: Remove outdated entries from onlineusers collection', 'deletion_count': 0, 'file_extension': '.js', 'lang': 'js', 'license': 'mit', 'repo_name': '4minitz/4minitz'}