本文介绍了流星发布限制和排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下出版物:
Meteor.publish('times', function() {
return Times.find({}, {sort: {createdAt: -1}}, {limit: 5});
})
这将返回所有记录,忽略限制.然而这
This returns all records, limit is ignored. However this
Meteor.publish('times', function() {
return Times.find({}, {limit: 5});
})
返回 5 条记录,但顺序错误.如何对出版物进行限制和排序?
returns 5 records, but in the wrong order. How do I limit and sort in a publication?
推荐答案
参见 forEach 部分的文档,以及 find 的文档.limit
是 options
对象的一个键,所以应该是:
See the example in the forEach section of the docs, and the documentation for find. limit
is a key of the options
object, so it should be:
Times.find({}, {sort: {createdAt: -1}, limit: 5});
请注意,如果您希望在客户端上按排序顺序排列文档,则需要 在您的模板代码中重新排序.
Note that if you want the documents in sorted order on the client, you will need to sort them again in your template code.
这篇关于流星发布限制和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!