File tree 1 file changed +28
-0
lines changed
src/main/asciidoc/reference
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -1821,6 +1821,34 @@ List<Person> findByFirstname(String firstname);
1821
1821
----
1822
1822
====
1823
1823
1824
+ [[mongo.query.kotlin-support]]
1825
+ === Typed Queries for Kotlin
1826
+
1827
+ https://kotlinlang.org/docs/reference/reflection.html#property-references[Kotlin property references]
1828
+ can be used to build typed queries.
1829
+
1830
+ Spring provides several infix extension functions that return a `Criteria` object,
1831
+ like `isEqualTo` and `regex`.
1832
+
1833
+ ====
1834
+ [source,kotlin]
1835
+ ----
1836
+ import org.springframework.data.mongodb.core.query.*
1837
+
1838
+ class Author(val name: String)
1839
+ class Book(val name: String, val price: Int, val author: Author)
1840
+
1841
+ // Use Property References for field names
1842
+ mongoOperations.find<Book>(
1843
+ Query(Book::name isEqualTo "Moby-Dick")
1844
+ )
1845
+
1846
+ // Nested Properties (i.e. refer to "book.author")
1847
+ Book::author / Author::name regex "^H" <1>
1848
+ ----
1849
+ <1> The `/` operator (`div`) is used to construct nested properties.
1850
+ ====
1851
+
1824
1852
include::../{spring-data-commons-docs}/query-by-example.adoc[leveloffset=+1]
1825
1853
include::query-by-example.adoc[leveloffset=+1]
1826
1854
You can’t perform that action at this time.
0 commit comments