In KeystoneJS we are currently using aggregation to query Mongo and just grabbing the whole set and returning that. Now, that we're getting more data, we need to paginate. KeystoneJS supports pagination, but from the looks of it is only supporting the find command in the where option parameter. Is there any way that the pagination provided by KeystoneJS can paginate the results from an aggregation query?
Example aggregate query:
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');
The results that return back from this I would like to be able to paginate through. I am exploring using mongoose to do it or just filtering through the array with javascript, but since I see that Keystone has pagination built in, I wanted to ask the contributors if this is supported.