Skip to content

Invalid condition generation in filtered positional operator  #440

@nmarcin92

Description

@nmarcin92

Using the exact example from docs:
https://www.mongodb.com/docs/manual/reference/operator/update/positional-filtered/#update-all-array-elements-that-match-arrayfilters

case class Grades(id: Grades.ID, grades: List[Grade]) extends MongoEntity[Int]
object Grades extends MongoEntityCompanion[Grades]

case class Grade(grade: Int, mean: Int, std: Int)
object Grade extends MongoDataCompanion[Grade]

val update = Grades.ref(_.grades).updateFiltered(
 filter = _.ref(_.grade).gte(85),
 update = _.ref(_.mean).set(100)
)

We can see that the generated array query looks as follow:

println(update.toBsonAndArrayFilters._2.asScala.head.toJson)
> {"filter0": {"grade": {"$gte": 85}}}

instead of {"filter0.grade" : {"$gte": 85}}}

This actually matches on documents in the array that are equal to {"grade": {"$gte": 85}}, instead of evaluating the condition on its fields, so it makes it impossible to actually query the documents in array.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions