Problem: To Implement Pagination on the server side using Ktor and Kmongo.
Tech Stacks:
Kotlin as Programming Language.
Ktor as Web Framework.
MongoDb as database.
Kmongo as Sql framework.
I cannot find any tutorial or posts that describes to implement pagination with Database in Ktor.
This is how I implemented the same.
override suspend fun getAllUsers(page: Int, limit: Int): List<User> {
return database.getCollection<User>().find().skip(skip = (page - 1) * limit).limit(limit = limit)
.partial(true).descendingSort(User::lastLoginTime).toList()
}
Thanks to @Aleksei Tirman.
For More see - https://stackoverflow.com/a/15387497/13963150