MongoDB
 sql >> Datenbank >  >> NoSQL >> MongoDB

Hat Meteor eine eigene Abfrage für Sammlungen?

Collection.find({}).distinct('myField', true);

Fügen Sie zur Verwendung Folgendes in [project]/client/lib/a.js:

ein
LocalCollection.Cursor.prototype.distinct = function (key,random) {
  var self = this;

  if (self.db_objects === null)
    self.db_objects = self._getRawObjects(true);
  if (random)
    self.db_objects = _.shuffle(self.db_objects);
  if (self.reactive)
    self._markAsReactive({ordered: true,
                          added: true,
                          removed: true,
                          changed: true,
                          moved: true});
  var res = {};
  _.each(self.db_objects,function(value){

    if(!res[value[key]]){
        res[value[key]] = value;
    }
  });
  return _.values(res);
};