Meteor doesn’t support distinct in query. Say, i have a dataset as follow.
{ "student": [ { "_id": "1", "class": "1A", "name": "Peter" }, { "_id": "2", "class": "1A", "name": "Jack" }, { "_id": "3", "class": "1B", "name": "Mary" }, { "_id": "4", "class": "1C", "name": "Sam" }, { "_id": "5", "class": "1C", "name": "Ann" }, ] }
What i would like to know is how many distinct classes are there. Here is the solution suggested by Jonathan Pidgeon from Empire5Design.
function getDistinctClasses() { var data = Student.find().fetch(); var distinctData = _.uniq(data, false, function(d) {return d.class}); return _.pluck(distinctData, "class"); }
Done =)
Reference: coderwall – Get unique values from a collection in Meteor
And what if you have a very large collection? Say 10000 documents…?
LikeLike
Maybe you could try meteor-aggregate.
LikeLike