Mongodb Meteor对集合有不同的查询吗?

Mongodb Meteor对集合有不同的查询吗?,mongodb,meteor,Mongodb,Meteor,我想返回集合中不同的字段。我知道这些都是问题所在,但我对查询语言不够熟悉,不知道这是否可行 Meteor.publish("distinctCollection", function() { return Collection.find({ ... }, fields: { "myField": 1 }); }); 要使用,请将以下内容放在[project]/client/lib/a.js中: LocalCollection.Cursor.prototype.distinct = fu

我想返回集合中不同的字段。我知道这些都是问题所在,但我对查询语言不够熟悉,不知道这是否可行

Meteor.publish("distinctCollection", function() {
    return Collection.find({ ... }, fields: { "myField": 1 });
});
要使用,请将以下内容放在[project]/client/lib/a.js中:

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);
};

谢谢我将尝试此方法。使用此方法,我是否能够自定义
find()
,以使某些操作仅为被动操作?那么它唯一的反应就是添加和删除?是的。在self中。_markAsReactive()设置为false:有序、更改、移动。我想它被称为_depend,但它并不像我预期的那样工作。不像Mongo的。我只想自己滚。在0.6.5.1之后,上面的解决方案不起作用。改为检查这个:或者陨石上的包裹:检查这个整洁的解决方案[链接]
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);
};