Meteor: how to search for only distinct field values aka a collection.distinct("fieldname") similar to Mongo's -


I am using meteor, and I am trying to find only different (unique) values ​​of a field . Mongodb has a command

  archive ("Field name");   

but it is not applicable to Mongo for Meteor drivers I tried to use the meteor-mongo-extensions package but client-side Collection.distinct ("fieldname") For the client console still has "undefined";

What, essentially, is looking a specific?

I think this is such a basic question - for example, a list of students with their teachers as a field, and then the list of students is done by teachers outside of it, For example ...

If I can wrap my lazy delusional brain around the general concept, then maybe I can do some success.

You only underscore. You can use JS, which comes with meteorite - the recommended use case should be OK. If you try this on a large data set or run it frequently, you can participate in performance issues, but it should be enough to use common-or-garden:

  var distinctEntries = _.uniq Collection.find ({}, {sort: {myField: 1}, field: {myField: true}}). Fetch () Map (function (x) {return x.myField;}), true);   

This will return special entries in myField for all documents in archive . If the one-liner looks a bit insufficient then the apology; The sort and fields options and true are just for making it more efficient.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -