I’m looking for a way to get a list of the unique values of a specific field.
The scenarios below are completely imaginary.
Let’s say I have answeredBy field in collection ClientCalls. It contains the username of who answered the call. Teh first phase is to get a list of all the users who answered calls today, in a publication. The next phase is to include the counts in a similar publication.
Let’s say there were 5k answered client calls today. There is a page where the manager selects from the list of who answered calls today. Then s/he sees that person’s answers to client calls.
So I want to get a list of personnel who answered calls today. I need to return unique values of ClientCalls.answeredBy.
I can easily do
var Records = ClientCalls.find({answeredDate: Today}, {fields: {Personnel: 1}}).fetch()
return _.uniq(_.pluck(Records, 'Personnel')
and this gives me the list I need, but doing this in a publication causes Error: Publish function returned an array of non-Cursors
.
I could easily return all the calls in a publication and do the uniq on the clientside, but it would mean a lot of unnecessary resource usage.
In the Meteor docs, it says to use .find() to create cursors.
So, how do I return a list of unique usernames as a cursor?