Search code examples
mongodbmeteordistinctmeteor-blaze

Meteor get unique items from a collection


I have a collection Files which contain items with a userId. I want a unique array with all userIds in the collection.

Here my first approach (code from here: LINK)

Server Method

'uniqUser': function(){
  const distinct = Meteor.wrapAsync(Files.rawCollection().distinct,Files.rawCollection());
  const result = distinct('userId');
  console.log(result)
  return result
}

Client Call

uniqUser(){
  Meteor.call('uniqUser', function(err, data) {
    console.log(data);
    return data;
  });
}

the console.log looks good: enter image description here

but my view show nothing!? also no errors...

uniqUser:
{{#each uniqUser}}
  <p>{{this}}</p>
{{/each}}

Solution

  • I have to use meteor-reactive-method LINK:

      uniqUser() {
         return ReactiveMethod.call("uniqUser");
      }
    

    and eveything is fine!