Skip to content

Commit e348980

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

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/main/asciidoc/reference/mongodb.adoc

+28
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,34 @@ List<Person> findByFirstname(String firstname);
18211821
----
18221822
====
18231823

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+
18241852
include::../{spring-data-commons-docs}/query-by-example.adoc[leveloffset=+1]
18251853
include::query-by-example.adoc[leveloffset=+1]
18261854

0 commit comments

Comments
 (0)