File tree 1 file changed +32
-0
lines changed
src/main/asciidoc/reference
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -1821,6 +1821,38 @@ 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
+ Most methods in `Criteria` have a matching Kotlin extension, like `inValues` and `regex`.
1831
+
1832
+ ====
1833
+ [source,kotlin]
1834
+ ----
1835
+ import org.springframework.data.mongodb.core.query.*
1836
+
1837
+ mongoOperations.find<Book>(
1838
+ Query(Book::name isEqualTo "Moby-Dick") <1>
1839
+ )
1840
+
1841
+ // vararg & infix variations
1842
+ Book::category.inValues("Fantasy", "Science fiction")
1843
+ Book::category inValues listOf("Fantasy", "Science fiction")
1844
+
1845
+ // Binary operators
1846
+ BinaryMessage::payload bits { allClear(0b101) } <2>
1847
+
1848
+ // Nested Properties (i.e. refer to "book.author")
1849
+ Book::author / Author::name regex "^H" <3>
1850
+ ----
1851
+ <1> `isEqualTo()` is an infix extension function with receiver type `KProperty<T>` that returns `Criteria`.
1852
+ <2> For bitwise operators, pass a lambda argument where you call one of the methods of `Criteria.BitwiseCriteriaOperators`.
1853
+ <3> To construct nested properties, use the `/` character (overloaded operator `div`).
1854
+ ====
1855
+
1824
1856
include::../{spring-data-commons-docs}/query-by-example.adoc[leveloffset=+1]
1825
1857
include::query-by-example.adoc[leveloffset=+1]
1826
1858
You can’t perform that action at this time.
0 commit comments