Skip to content

Commit 796a282

Browse files
committed
DATAMONGO-2138 - Document Typed Queries
1 parent 447ccb2 commit 796a282

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/main/asciidoc/reference/mongodb.adoc

+35
Original file line numberDiff line numberDiff line change
@@ -1792,6 +1792,41 @@ GeoResults<Jedi> results = mongoOps.query(SWCharacter.class)
17921792
----
17931793
====
17941794

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+
17951830
[[mongo.query.additional-query-options]]
17961831
=== Additional Query Options
17971832

0 commit comments

Comments
 (0)