Pagination with sort
Is there a way to have a paginated query return items in some specific sorted order. I'm trying to query messages using paginate() and sort them by messageId instead of asc/desc in creation time
4 Replies
you can query with a sorted order by adding an index on messageId and querying
withIndex
, then calling paginate()
on that should give you the paginated messages in that orderI have two properties
conversationId
and messageId
. My messages are indexed by conversationId
, so when I query using withIndex, so the returned array of documents aren't sorted by messageId
.You can make a multi-field index on ["conversationId", "messageId"], and do the query to get pages of the messages within a conversation by message id descending
ah okay makes sense thank you
let me give that a shot