Kotlin Driver - Allow querying nested properties via data classes
In the Kotlin driver extensions, we can use data class KProperties to create Filters. For example given these models as data classes:
data class Movie(val movieName: String, releaseDate: LocalDate, rating: String)
data class MovieReview(val movie: Movie, val rating: Double, val review: String, val reviewerName: String)
If I wanted to query a movie review by its rating I could simply write:
MovieReview::rating gte .8
but if I wanted to query a MovieReview by the movie name I cannot currently do:
MovieReview::movie.movieName eq "Mobile Suit Gundam: Char's Counterattack"
I believe KMongo has the ability to do this by overloading the /
operator so I could query like:
MovieReview::movie / Movie::movieName eq "Mobile Suit Gundam: Char's Counterattack"
I think a similar feature should be included in the kotlin driver extensions to avoid have to switch between query methods. The examples for the queries in the documentation uses overly simplistic Models which is good to start but it shouldn't be explicitly stated that you cannot query nested properties via data classes.

-
Hey Geoffrey, just wanted to confirm that the div operator is available via the kotlin extensions mongodb-driver-kotlin-extensions (5.3.1).
For example:
data class Movie(val movieName: String, val releaseDate: Int, val rating: String)
data class MovieReview(val movie: Movie, val rating: Double, val review: String, val reviewerName: String)
@Test
fun testMovie() {
val bson = MovieReview::movie / Movie::movieName eq "Mobile Suit Gundam: Char's Counterattack"
assertEquals("{\"movie.movieName\": \"Mobile Suit Gundam: Char's Counterattack\"}", bson.toBsonDocument().toJson())
} -
Thanks for the feature request Geoffrey. I've filed https://jira.mongodb.org/browse/JAVA-5803 to track this.