I'm quite new to Meteor and I'd really appreciate some advice.
I have two collections, the Meteor users collection and a collection called awards. The awards collection contains a field named nominees which contains an array of strings which contain the user _ids from the users collection. An awards document looks like this.
{
"nominees" : [
"fuEaF9mfMDpYzXFh6",
"3NBiDrwM63h4J6QKh"
],
"reason" : "Award reason...",
"nominator" : "HRD5ozqMNcx6boXQR",
"_id" : "ozi6wio9EdStvja9J"
}
I need to have a league table on the client for users with the most nominated awards.
I've seen some samples for collecting counts of all documents in a collection. for example Meteor subscribe to a count
But I want something like a dictionary array on the client with one entry for each user, with two values, the users _id and the total count of nominations for the user.
I can run something like this to get the data I need but if a limit is applied on the client collection, this is only accurate on the server, I need a way of getting this data to the client.
I'm assuming I'll need to publish a subscription, subscribe on the client and create a local collection for this on the client but I'm unsure how'd I'd go about this.
Meteor.users.find().fetch().map(function(it) {
return {
'fullName': it.profile.fullName,
'awardsCount': Awards.find({
nominees: {
$in: [it._id]
}
}).count()
};
});
Any help would be greatly appreciated.