Skip to content

Commit 11c993d

Browse files
committed
DATAMONGO-2138 - Update typedCriteriaSample
1 parent 8fa107d commit 11c993d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/query/TypedCriteriaExtensions.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package org.springframework.data.mongodb.core.query
1717

18+
import org.springframework.data.mongodb.core.MongoOperations
19+
import org.springframework.data.mongodb.core.find
20+
1821
/**
1922
* Build [Criteria] with type-safe field names.
2023
*
@@ -40,12 +43,19 @@ fun typedCriteria(vararg operations: TypedCriteria): Criteria {
4043
fun typedQuery(vararg criteria: TypedCriteria): Query =
4144
Query(typedCriteria(*criteria))
4245

43-
private fun typedCriteriaSample() {
46+
private fun typedCriteriaSample(mongoOperations: MongoOperations) {
4447
class Author(val name: String)
4548
class Book(val name: String, val price: Int, val author: Author)
4649
// Use Property References for field names
50+
mongoOperations.find<Book>(
51+
Query(
52+
Book::name isEqualTo "Moby-Dick"
53+
)
54+
)
55+
// Chain with typedCriteria()
4756
typedCriteria(
48-
Book::name isEqualTo "Moby-Dick",
57+
Book::author elemMatch
58+
(Author::name isEqualTo "Herman Melville"),
4959
Book::price exists true
5060
)
5161
// $or, $nor, $and operators

0 commit comments

Comments
 (0)