File tree 1 file changed +35
-0
lines changed
src/main/asciidoc/reference
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -1792,6 +1792,41 @@ GeoResults<Jedi> results = mongoOps.query(SWCharacter.class)
1792
1792
----
1793
1793
====
1794
1794
1795
+ [[mongo.query.kotlin-support]]
1796
+ === Type-safe Queries for Kotlin
1797
+
1798
+ https://kotlinlang.org/docs/reference/reflection.html#property-references[Kotlin property references]
1799
+ can be used to build type-safe queries.
1800
+
1801
+ Most methods in `Criteria` have a matching Kotlin extension, like `inValues` and `regex`.
1802
+
1803
+ ====
1804
+ [source,kotlin]
1805
+ ----
1806
+ import org.springframework.data.mongodb.core.query.*
1807
+
1808
+ mongoOperations.find<Book>(
1809
+ Query(Book::title isEqualTo "Moby-Dick") <1>
1810
+ )
1811
+
1812
+ Book::title exists true
1813
+
1814
+ Criteria().andOperator(
1815
+ Book::price gt 5,
1816
+ Book::price lt 10
1817
+ )
1818
+
1819
+ // Binary operators
1820
+ BinaryMessage::payload bits { allClear(0b101) } <2>
1821
+
1822
+ // Nested Properties (i.e. refer to "book.author")
1823
+ Book::author / Author::name regex "^H" <3>
1824
+ ----
1825
+ <1> `isEqualTo()` is an infix extension function with receiver type `KProperty<T>` that returns `Criteria`.
1826
+ <2> For bitwise operators, pass a lambda argument where you call one of the methods of `Criteria.BitwiseCriteriaOperators`.
1827
+ <3> To construct nested properties, use the `/` character (overloaded operator `div`).
1828
+ ====
1829
+
1795
1830
[[mongo.query.additional-query-options]]
1796
1831
=== Additional Query Options
1797
1832
You can’t perform that action at this time.
0 commit comments