我想在我的集合中返回不同的字段。我知道这些是mongo 运算符的文档,但我对查询语言不够熟悉,不知道这是否可能?
Meteor.publish("distinctCollection", function() {
return Collection.find({ ... }, fields: { "myField": 1 });
});
我想在我的集合中返回不同的字段。我知道这些是mongo 运算符的文档,但我对查询语言不够熟悉,不知道这是否可能?
Meteor.publish("distinctCollection", function() {
return Collection.find({ ... }, fields: { "myField": 1 });
});
Collection.find({}).distinct('myField', true);
要使用,请将以下内容放在 [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);
};