【问题标题】:meteor publish with limit and sort流星发布限制和排序
【发布时间】:2014-12-13 08:47:02
【问题描述】:

我有以下出版物:

Meteor.publish('times', function() {
    return Times.find({}, {sort: {createdAt: -1}}, {limit: 5});
})

这将返回所有记录,忽略限制。不过这个

Meteor.publish('times', function() {
    return Times.find({}, {limit: 5});
})

返回 5 条记录,但顺序错误。如何在出版物中限制和排序?

【问题讨论】:

    标签: meteor


    【解决方案1】:

    请参阅文档的forEach 部分中的示例,以及find 的文档。 limitoptions 对象的键,所以应该是:

    Times.find({}, {sort: {createdAt: -1}, limit: 5});
    

    请注意,如果您希望文档在客户端上按排序顺序排列,则需要在模板代码中输入sort them again

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-20
      • 2014-09-24
      • 2014-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      相关资源
      最近更新 更多