Skip to content

Commit

Permalink
Fix $elemMatch documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
denis_savitsky committed Jan 27, 2024
1 parent 6d6821b commit d3a7e83
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,15 @@ val q = query[Course](_.studentNames.length == 20)
```scala
import oolong.dsl.*

case class Course(studentNames: List[String], tutor: String)
case class Student(name: String, age: Int)

val q = query[Course](_.studentNames.exists(_ == 20)) // $elemMatch ommited when querying single field
// q is {"studentNames": 20}
case class Course(students: List[Student], tutor: String)

val q = query[Course](course => course.studentNames.exists(_ > 20) && course.tutor == "Pavlov")
// q is {"studentNames": {"$elemMatch": {"studentNames": {"$gt": 20}, "tutor": "Pavlov"}}}
val q = query[Course](_.students.exists(_.age == 20)) // $elemMatch ommited when querying single field
// q is {"students.age": 20}

val q = query[Course](course => course.students.exists(st => st.age > 20 && st.name == "Pavel"))
// q is {"students": {"$elemMatch": {"age": {"$gt": 20}, "name": "Pavel"}}}

```

Expand Down

0 comments on commit d3a7e83

Please sign in to comment.