gpt4 book ai didi

meteor 发布限制和排序

转载 作者:行者123 更新时间:2023-12-04 03:00:49 26 4
gpt4 key购买 nike

我有以下出版物:

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

这将返回所有记录,忽略限制。然而这
Meteor.publish('times', function() {
return Times.find({}, {limit: 5});
})

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

最佳答案

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

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

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

关于 meteor 发布限制和排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26430591/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com