在KeystoneJS中,我们正在使用聚合来查询Mongo并只抓取整个集合并返回它。现在,我们正在获取更多数据,我们需要分页。 KeystoneJS支持分页,但从外观上看,它只支持where选项参数中的find命令。有没有什么办法可以使KeystoneJS提供的分页能够对聚合查询的结果进行分页?KeystoneJS列表聚合结果的分页
实例汇总查询:
keystone.list('Posts').model.aggregate([
{'$match': {"state":"published"}},
{'$unwind': {'path':"$actions", 'preserveNullAndEmptyArrays': false}},
{'$lookup': {
'from':"actions",
'localField': "actions",
'foreignField': "_id",
'as': "actions"}},
{'$match': {"actions.key": action}},
{'$unwind': {'path':"$postTopics"}},
{'$lookup': {
'from':"posttopics",
'localField': "postTopics",
'foreignField': "_id",
'as': "posttopics"}},
{'$match': {"posttopics.key": topic}},
{'$unwind': {'path':"$postSubTopics"}},
{'$lookup': {
'from':"postsubtopics",
'localField': "postSubTopics",
'foreignField': "_id",
'as': "postsubtopics"}},
{'$match': {"postsubtopics.key": subtopic}},
{'$unwind':
{'path':"$postSubTopics",
'preserveNullAndEmptyArrays': true}},
{'$unwind':
{'path':"$postTopics",
'preserveNullAndEmptyArrays': true}},
{'$lookup': {
'from':"postsubtopics",
'localField': "postSubTopics",
'foreignField': "_id",
'as': "postsubtopics"}},
{'$lookup': {
'from':"posttopics",
'localField': "postTopics",
'foreignField': "_id",
'as': "posttopics"}},
{'$match': {
'$or':
[
{ "postsubtopics.searchKeywords": keyword },
{ "posttopics.searchKeywords": keyword }
]
}}
]).sort('-publishedDate');
,从这个我想是能够通过分页返回回来的结果。我正在探索使用猫鼬做它,或者只是用javascript过滤数组,但是由于我看到Keystone已经内置了分页,我想问问贡献者是否支持。
感谢您的意见。我已经尝试过上面显示的查询,并且尝试了很多变体,但都没有奏效。你上面的例子抱怨聚合不是一个函数。我确实已经掌握了所有数据,并使用JS自己执行分页。 Mongo中的聚合框架似乎越来越流行,我只是好奇,是否有一个简单的即插即用的keystone分页来支持聚合而不是find查询。 – lshaffer