I'm making a two player game where the users sign in with twitter. If I search in the console to see if there are users logged on ( Meteor.users.find().count()
) It returns the number of users ever to be logged in. After learning this I installed the userstatus package with meteorite. db.users.find({'status.online' : true}).count()
using the terminal to start Meteor mongodb in my directory shows me the number of users currently connected. I have made a collection called games to start separate games for each two unique users. My guess for the next step is to search users and push them in to an array. I want to search if there is more than 1 user logged in and initialize a game if the right condition is met(2 users logged in). How do I check if there are enough users logged in instead of db.users.find().count()
in my if(Meteor.isServer){}
portion of my code?
the github repo gives two examples, both in coffeescript, I converted them to Javascript using http://js2coffee.org/#coffee2js
https://github.com/mizzao/meteor-user-status
"You can use a reactive cursor to select online users either in a publish function or a template helper:"
Option One: Publish Function:
Meteor.publish("userStatus", function() {
return Meteor.users.find({
"status.online": true
}, {
fields: {...}
});
});
Option Two: Template Helper:
Template.foo.usersOnline = function() {
return Meteor.users.find({
"status.online": true
});
};