我开发了一个web应用程序,并使用MongoDB存储数据。我能够对数据进行排序并正确地显示它,但是我希望在使用Mongo排序之后得到对象的位置。到目前为止,我有这样的代码:
Websites.find({_id: {$lte: website_id}}, {sort:{upvotes: -1}}).count();
不太好用。它返回某种位置,但与sort:{upvotes: -1}
无关。
因此,问题是,如何将1
返回到最受欢迎的位置,如何将2
返回到第二个,等等?
发布于 2016-04-24 12:04:20
这就是你能做到的。
<template name="websites">
<h2>My Websites list</h2>
<div class="row">
{{#each websites}}
Index:{{@index}}
Feild1:{{feild1}}
Feild2:{{feild1}}
...
{{/each}}
</div>
</template>
Template.websites.helpers({
websites: function () {
return Websites.find({_id: {$lte: website_id}}, {sort:{upvotes: -1}});
},
index: function (index) {
return ++index;
},
})
我没有创建任何表或列表,但根据您的要求,您也可以添加该表或列表。我希望干草能解决问题。
发布于 2016-04-23 18:22:10
Websites.find({_id: {$lte: website_id}}, {sort:{upvotes: -1}}).fetch()
https://stackoverflow.com/questions/36814284
复制相似问题