-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Optimization
-
Fully Compatible
-
ALL
-
v8.0
-
QO 2024-04-01
-
54
https://jira.mongodb.org/browse/BF-32195 was caused by a partial unique index that includes this filter in an OR
"$and" : [ { "obj.obj.obj.obj.obj.obj.num" : { "$type" : "long" } } ]
This query results in differing unique index behavior on the two versions.
db.fuzzer.runCommand({ "update" : "fuzzer", "updates" : [ { "q" : { }, "u" : [ { "$addFields" : { "obj.obj.obj.obj.obj.obj.num" : { "$mod" : [ NumberLong("314159265358979383"), 34928 ] } } } ], "multi" : true } ]})
The $mod on 7.0 produces a long (and so send every document in the collection to the index, resulting in a duplicate key error). On 7.3 / 8.0 it produces an int and does not result in a duplicate key error.
https://jira.mongodb.org/browse/DEVPROD-5208 resolved a similar issue.
Avoiding "$type" : "long" anywhere in a partial unique index's filter should resolve the issue.