Loading...
Loading...
We have come across a problem that was introduced with this change: SERVER-34012. The exact line causing this is https://github.com/mongodb/mongo/blame/master/src/mongo/db/matcher/expression_tree.cpp#L250. This problem can only be seen on MongoDB v5, earlier versions work properly. Steps to reproduce: Create "some" collection and then run: db.getCollection("some").aggregate({$match: { "$or" : [ { "x" : "a" }, { "x" : "b" }, { "x" : /c/ }] } }) Expected output: No failure. Output: uncaught exception: Error: command failed: { "ok" : 0, "errmsg" : "Failed to optimize pipeline :: caused by :: Failed to optimize expression :: caused by :: Incorrect number of non-equivalent expressions", "code" : 3401204, "codeName" : "Location3401204" } with original command request: { "aggregate" : "FileNodeVersions", "pipeline" : [ { "$match" : { "$or" : [ { "x" : "a" }, { "x" : "b" }, { "x" : /c/ } ] } } ], "cursor" : { }, "lsid" : { "id" : UUID("af1c7696-912f-4ad8-a53b-8eb9db5c0162") }
xgen-internal-githook commented on Thu, 2 Jun 2022 13:30:42 +0000: Author: {'name': 'Timour Katchaounov', 'email': 'timour.katchaounov@mongodb.com', 'username': 'timourk'} Message: SERVER-66379 $or to $in conversion flawed (cherry picked from commit 951197b3834d509d7903efa4a66c0e9f79235262) (cherry picked from commit b499c915d1c21f063548c96d5d547dcfcda55754) Branch: v5.0 https://github.com/mongodb/mongo/commit/ea79d55381c353e84cd673c4b21deb0b0ea4826e xgen-internal-githook commented on Thu, 2 Jun 2022 11:27:22 +0000: Author: {'name': 'Timour Katchaounov', 'email': 'timour.katchaounov@mongodb.com', 'username': 'timourk'} Message: SERVER-66379 $or to $in conversion flawed (cherry picked from commit 951197b3834d509d7903efa4a66c0e9f79235262) Branch: v6.0 https://github.com/mongodb/mongo/commit/b499c915d1c21f063548c96d5d547dcfcda55754 xgen-internal-githook commented on Tue, 31 May 2022 15:18:28 +0000: Author: {'name': 'Timour Katchaounov', 'email': 'timour.katchaounov@mongodb.com', 'username': 'timourk'} Message: SERVER-66379 $or to $in conversion flawed Branch: master https://github.com/mongodb/mongo/commit/951197b3834d509d7903efa4a66c0e9f79235262 JIRAUSER1258247 commented on Thu, 26 May 2022 09:46:29 +0000: It turns out the collation is crucial. This is a reproducible test case: db.createCollection("some"); db.getCollection("some").find({ "$or" : [ { "x" : "a" }, { "x" : "b" }, { "x" : /c/ }] }).sort({ name: 1 }).collation({ locale: 'en_US'}) JIRAUSER1258247 commented on Thu, 26 May 2022 09:39:03 +0000: Update: I read the original thread on Stackoverflow, and tested the complete example in the thread. Ineed, the original much bigger query results in the reported assertion. So there is a bug, but the test case here seems to have been oversimplified. I will simplify it a bit before continuing work on the bug. JIRAUSER1258247 commented on Thu, 26 May 2022 09:13:17 +0000: Unfortunately I cannot reproduce the problem on neither master, nor v5.0. This is what I tried: test> db.createCollection("some"); { ok: 1 } test> db.getCollection("some").aggregate({$match: { "$or" : [ { "x" : "a" }, { "x" : "b" }, { "x" : /c/ }] } }) test> db.some.insertOne({x:"a"}) { acknowledged: true, insertedId: ObjectId("628f440bda50c4aecee984f3") } test> db.getCollection("some").aggregate({$match: { "$or" : [ { "x" : "a" }, { "x" : "b" }, { "x" : /c/ }] } }) [ { _id: ObjectId("628f440bda50c4aecee984f3"), x: 'a' } ] daniel.hegener@gmx.net could you please provide exact instructions how to reproduce - exact version (or commit), how it was built, complete script. JIRAUSER1256534 commented on Wed, 11 May 2022 11:35:49 +0000: https://stackoverflow.com/questions/69098410/mongodb-failed-with-error-failed-to-optimize-expression
MongoDB Integration
Learn more about where this data comes from
Bug Scrub Advisor
Streamline upgrades with automated vendor bug scrubs
BugZero Enterprise
Wish you caught this bug sooner? Get proactive today.