invirt.data.mongodb.data.kt Maven / Gradle / Ivy
package invirt.data.mongodb
import com.mongodb.client.model.Sorts
import com.mongodb.kotlin.client.FindIterable
import invirt.data.Page
import invirt.data.Sort
import invirt.data.SortOrder
import org.bson.conversions.Bson
fun FindIterable.page(page: Page): FindIterable {
return this.skip(page.from)
.limit(page.size)
}
fun Sort.mongoSort(): Bson {
return when (order) {
SortOrder.ASC -> Sorts.ascending(field)
SortOrder.DESC -> Sorts.descending(field)
}
}
fun FindIterable.sort(sort: Sort?): FindIterable {
return if (sort != null) {
this.sort(sort.mongoSort())
} else {
this
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy