Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Will Not Implement
Created by Guest
Created on Feb 28, 2025

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.
  • Guest
    Mar 10, 2025
    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()) }
  • Guest
    Feb 28, 2025
    Thanks for the feature request Geoffrey. I've filed https://jira.mongodb.org/browse/JAVA-5803 to track this.