Hi, I’m trying to build a sort BSON to give to my ...
# kmongo
r
Hi, I’m trying to build a sort BSON to give to my find request from a string, representing my path to the property in my collection’s class. Do you know how I could do it? I managed to do it when the properties are not nested but it’s trickier when I’m trying to access a property of one of my class properties...
Copy code
fun <E : Any> SortProperty.toSortBson(kClass: KClass<E>): Bson {
    val kProperty = kClass.memberProperties.find { it.name == this.property }
        ?: throw InvalidSortPropertyException(this.property, kClass.simpleName)

    return if (this.direction == SortDirection.ASC) {
        ascending(kProperty)
    } else {
        descending(kProperty)
    }
}