I have read several articles about distinct queries and can’t put it to work for me. I have read underscore but in the end the only thing i get is: “Exception from sub “foo” id mgqThnxXtjSdwGP8T Error: Publish function returned an array of non-Cursors”
I want to get a full list of my data, with distinct field (no repeating), using meteor publish (if possible).
Your code is returning an array of npatrimonio fields instead of returning distinctData.
And it would be much better if you fetched only the needed field instead of the entire database.
What you are doing with the above code is returning an array of npatrimonio. This is what you are returning: [1,2,3]. But it should be more like [{npatrimonio:1}, {npatrimonio:2}, {npatrimonio:3}].
[quote=“nlammertyn, post:7, topic:17443”]
For distinct queries you should use a method and the rawcollection. _.uniq is inefficient
[/quote]Wouldn’t a method lose Optimistic UI because rawcollection is server only? Seems like there are arguments for both approaches.
That’s absolutely true. It’ll probably depend on the use case, in general if I needed to run a distinct query it was on datasets that were large enough to compromise on the reactivity.