我有以下出版物:
Meteor.publish('times', function() {
return Times.find({}, {sort: {createdAt: -1}}, {limit: 5});
})
这将返回所有记录,忽略限制。然而这
Meteor.publish('times', function() {
return Times.find({}, {limit: 5});
})
返回 5 条记录,但顺序错误。如何对出版物进行限制和排序?
请参阅中的示例forEach http://docs.meteor.com/#foreach文档的部分,以及文档find http://docs.meteor.com/#find. limit
是一个关键options
对象,所以它应该是:
Times.find({}, {sort: {createdAt: -1}, limit: 5});
请注意,如果您希望文档在客户端上按排序顺序排列,则需要再次对它们进行排序 https://stackoverflow.com/questions/15153349/meteor-subscribe-doesnt-update-sort-order-of-collection在你的模板代码中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)