Skip to content

Commit 4fc3a3c

Browse files
authored
MONGOID-5236 Add Feature Flag: Existing $and clause in query is overwritten by where condition (#5147)
* MONGOID-5236 add docs and config tests * MONGOID-5236 add tests for new feature flag * MONGOID-5236 fix documentation * MONGOID-5236 use dots instead of :: * MONGOID-5236 refactor spec test and fix comment
1 parent 57aaebb commit 4fc3a3c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

source/reference/configuration.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,28 @@ for details on driver options.
272272
# (default: false)
273273
fix_embedded_alias_pluck_distinct: false
274274

275+
# In Mongoid 7.3.3 and earlier, there was a bug when adding expressions
276+
# using the #and function. In certain situations, an $and clause would be
277+
# lost and replaced by one of the previous $and clauses. This would
278+
# happen when using the same operator on the same field multiple times.
279+
# For example:
280+
#
281+
# Band.where(id: 1).and({year: {'$in' => [2020]}}, {year: {'$in' => [2021]}}).where(id: 2)
282+
#
283+
# yields the following criteria:
284+
#
285+
# <Mongoid::Criteria
286+
# selector: {"_id"=>1, "year"=>{"$in"=>[2020]}, "$and"=>[{"_id"=>2}]}
287+
# options: {}
288+
# class: Band
289+
# embedded: false>
290+
#
291+
# This is obviously incorrect as the {"$in"=>[2021]} clause is lost.
292+
# Notice that the clause is only lost when both clauses are added using
293+
# the #and function. Turning on this feature flag fixes this bug.
294+
# (default: false)
295+
fix_multiple_ands: false
296+
275297
# Include the root model name in json serialization. (default: false)
276298
include_root_in_json: false
277299

0 commit comments

Comments
 (0)