【发布时间】:2013-01-28 18:09:21
【问题描述】:
我在meteor中需要这个map/reduce函数: http://cookbook.mongodb.org/patterns/count_tags/
从所有条目中读取所有标签,并返回包含集合中数量的唯一标签列表
我将如何实现这一点。我正在使用独立的MongoDB。 集合布局:
[_id] => 1234
[headline] => My First Post
[body] => Alot of stuff
[isPrivat] =>
[tags] => Array (
[0] => test
[1] => php
[2] => perl
)
我找到了这个问题/答案,但我不能让它做我不想做的事情:
Does Meteor have a distinct query for collections?
什么是最优雅的方式来做到这一点。 感谢您的宝贵时间
【问题讨论】:
-
你试过用underscore.js'groupBy方法吗?
-
这给了我唯一的条目,但到目前为止还没有计数:
var taglist = Posts.find({}).distinct("tags"); taglist = _.uniq(_.flatten(_.pluck(taglist, 'tags')));