我正在使用Meteor。我想在我的页面中显示推荐的项目列表。我接近它首先找到用户投票标签并按发生顺序排序。
var tags = [{name: 'tag1'},{name: 'tag2'},{name:'tag1'},{name: 'tag3'}];
tagsShortedByOccurrence = _(tags).chain().countBy('name').pairs().sortBy(1).pluck(0).value();
//tagsShortedByOccurrence will be like ..['tag1','tag2','tag3']
现在我想查找带有该标签的项目,但按标签数组顺序排序。我怎么能这样做?
文件示例:
//item document:
doc1 = {
_id: 1,
....
tags: [
{name: 'tag1'},{name: 'tag2'}
]
}
doc2 = {
_id: ,
....
tags: [
{name: 'tag2'},{name: 'tag3'}
]
}
var itemsRecommended = Items.find({...¿?},{limit:1});
itemsRecommended = [{_id: 1}];
谢谢!