Mahesh Babu
Mahesh Babu

Reputation: 145

meteor return unique documents from collection

I am a newbie to development and Meteor brought me in. I have the following scripts:

In the Lib Folder

Transactions = new Meteor.Collection('transaction');

Server

Meteor.publish('trans',function(){
    return Transactions.find({});
});

Client

Meteor.subscribe('trans');

My Collection named Transactions contains the following objects

{
  date: Date,
  amount: Number,
  userid: Meteor.userId()
}

I would like to return a list of all the different dates contained in the collection, without any duplicate.

Upvotes: 1

Views: 585

Answers (2)

Mahesh Babu
Mahesh Babu

Reputation: 145

Template.view.helpers({

viewDate:function(){
 var transactions = Transactions.find({userid:Meteor.userId()}).fetch();
return _.uniq(transactions, false, function(transaction) {return transaction.date});
}

});

This made my day... Thank You @chrishillonline

Upvotes: 3

chrishillonline
chrishillonline

Reputation: 25

return _.uniq(Transactions.find({}), function(transaction) {return JSON.stringify(transaction)});

Upvotes: 0

Related Questions