@@ -125,33 +125,27 @@ class FiltersSpec extends BaseSpec {
125
125
toBson(model.Filters .and()) should equal(Document (""" {$and : []}""" ))
126
126
}
127
127
128
- it should " and should render and without using $and" in {
128
+ it should " and should render using $and" in {
129
129
toBson(model.Filters .and(model.Filters .eq(" x" , 1 ), model.Filters .eq(" y" , 2 ))) should equal(
130
- Document (""" {x : 1, y : 2}""" )
131
- )
132
- }
133
-
134
- it should " and should render $and with clashing keys" in {
135
- toBson(model.Filters .and(model.Filters .eq(" a" , 1 ), model.Filters .eq(" a" , 2 ))) should equal(
136
- Document (""" {$and: [{a: 1}, {a: 2}]}""" )
130
+ Document (""" {$and: [{x : 1}, {y : 2}]}""" )
137
131
)
138
132
}
139
133
140
134
it should " and should flatten multiple operators for the same key" in {
141
135
toBson(model.Filters .and(model.Filters .gt(" a" , 1 ), model.Filters .lt(" a" , 9 ))) should equal(
142
- Document (""" {a : {$gt : 1, $lt : 9}}""" )
136
+ Document (""" {$and: [{ a : {$gt : 1}}, {a: { $lt : 9}}] }""" )
143
137
)
144
138
}
145
139
146
140
it should " and should flatten nested" in {
147
141
toBson(
148
142
model.Filters .and(model.Filters .and(model.Filters .eq(" a" , 1 ), model.Filters .eq(" b" , 2 )), model.Filters .eq(" c" , 3 ))
149
- ) should equal(Document (""" {a : 1, b : 2, c : 3}""" ))
143
+ ) should equal(Document (""" {$and: [{$and: [{ a : 1}, { b : 2}]}, { c : 3}] }""" ))
150
144
toBson(
151
145
model.Filters .and(model.Filters .and(model.Filters .eq(" a" , 1 ), model.Filters .eq(" a" , 2 )), model.Filters .eq(" c" , 3 ))
152
- ) should equal(Document (""" {$and:[{ a : 1}, {a : 2}, {c : 3}] }""" ))
146
+ ) should equal(Document (""" {$and: [{$and:[{ a : 1}, {a : 2}] }, {c : 3}] }""" ))
153
147
toBson(model.Filters .and(model.Filters .lt(" a" , 1 ), model.Filters .lt(" b" , 2 ))) should equal(
154
- Document (""" {a : {$lt : 1}, b : {$lt : 2} }""" )
148
+ Document (""" {$and: [{ a : {$lt : 1}}, { b : {$lt : 2} }] }""" )
155
149
)
156
150
toBson(model.Filters .and(model.Filters .lt(" a" , 1 ), model.Filters .lt(" a" , 2 ))) should equal(
157
151
Document (""" {$and : [{a : {$lt : 1}}, {a : {$lt : 2}}]}""" )
@@ -169,7 +163,7 @@ class FiltersSpec extends BaseSpec {
169
163
toBson(
170
164
model.Filters
171
165
.elemMatch(" results" , model.Filters .and(model.Filters .eq(" product" , " xyz" ), model.Filters .gt(" score" , 8 )))
172
- ) should equal(Document (""" { results : {$elemMatch : {product : "xyz", score : {$gt : 8}}}}""" ))
166
+ ) should equal(Document (""" { results : {$elemMatch : {$and: [{ product : "xyz"}, { score : {$gt : 8}}] }}}""" ))
173
167
}
174
168
175
169
it should " render $in" in {
0 commit comments