Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在MongoDB中查找集合属性的5个最大值_Mongodb_Meteor - Fatal编程技术网

在MongoDB中查找集合属性的5个最大值

在MongoDB中查找集合属性的5个最大值,mongodb,meteor,Mongodb,Meteor,MongoDB站点不工作 我正在用Meteor构建一个应用程序,我想为集合中的属性选择5个最大值。我怎样才能有效地做到这一点 这个怎么样: var items = MyCollection.find({}, { fields : { myAttribute : 1 }, // only fetch this filed sort : { myAttribute : -1 }, // sort by myAttribute (from large to small) limit

MongoDB站点不工作

我正在用Meteor构建一个应用程序,我想为集合中的属性选择5个最大值。我怎样才能有效地做到这一点

这个怎么样:

var items = MyCollection.find({}, {
  fields : { myAttribute :  1 }, // only fetch this filed
  sort   : { myAttribute : -1 }, // sort by myAttribute (from large to small)
  limit  : 5 // only take the first 5 elements
}).fetch();
这样,您将收到带有
\u id的
myAttribute
的文档。如果您只需要这些值,请执行以下操作:

var values = _.pluck(items, 'myAttribute');