File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
main/scala/com/avsystem/commons/mongo/typed
test/scala/com/avsystem/commons/mongo/typed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -45,9 +45,16 @@ sealed trait MongoUpdate[T] {
45
45
case ArrayElementsQualifier .FirstMatching () => " $"
46
46
case ArrayElementsQualifier .Each () => " $[]"
47
47
case ArrayElementsQualifier .Filtered (filter) =>
48
- val name = s " filter ${arrayFilters.size}"
49
- arrayFilters.add(Bson .document(name, filter.toBson))
50
- s " $$ [ $name] "
48
+ val identifier = s " filter ${arrayFilters.size}"
49
+ val (name, query) = filter match {
50
+ case MongoFilter .PropertyValueFilter (prop, propertyFilter) =>
51
+ // https://www.mongodb.com/docs/manual/reference/operator/update/positional-filtered/#update-all-documents-that-match-arrayfilters-in-an-array
52
+ identifier + MongoPropertyRef .Separator + prop.rawPath -> propertyFilter
53
+ case filter =>
54
+ identifier -> filter
55
+ }
56
+ arrayFilters.add(Bson .document(name, query.toBson))
57
+ s " $$ [ $identifier] "
51
58
}
52
59
53
60
val newPath = path + MongoPropertyRef .Separator + rawQualifier
Original file line number Diff line number Diff line change @@ -68,6 +68,10 @@ class MongoUpdateTest extends AnyFunSuite {
68
68
""" {"$set": {"intList.$[filter0]": 5}}, [{"filter0": {"$lt": 0}}]""" )
69
69
assert(toString(Rte .ref(_.innerList).updateAll(_.ref(_.int).set(5 ))) ==
70
70
""" {"$set": {"innerList.$[].int": 5}}, []""" )
71
+ assert(toString(Rte .ref(_.innerList).updateFiltered(_.ref(_.int).lt(0 ), _.ref(_.int).set(5 ))) ==
72
+ """ {"$set": {"innerList.$[filter0].int": 5}}, [{"filter0.int": {"$lt": 0}}]""" )
73
+ assert(toString(Rte .ref(_.innerList).updateFiltered(_.ref(_.intMap(" abc" )).lt(0 ), _.ref(_.int).set(5 ))) ==
74
+ """ {"$set": {"innerList.$[filter0].int": 5}}, [{"filter0.intMap.abc": {"$lt": 0}}]""" )
71
75
}
72
76
73
77
test(" compound updates" ) {
You can’t perform that action at this time.
0 commit comments