[SERVER-31042] MatchExpressionParser can discard sibling predicates of certain match expressions Created: 11/Sep/17  Updated: 30/Oct/23  Resolved: 12/Sep/17

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 3.5.12
Fix Version/s: 3.6.0-rc0

Type: Bug Priority: Major - P3
Reporter: David Storch Assignee: David Storch
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Query 2017-10-02
Participants:

 Description   

MatchExpressionParser::_parse() is intended to iterate through each top-level element of the match expression, parse that element, and add the result to an AndMatchExpression. In several cases, however, we instead return the result without adding it to the AndMatchExpression. One such case handles the $jsonSchema expression:

https://github.com/mongodb/mongo/blob/master/src/mongo/db/matcher/expression_parser.cpp#L586-L600

As a result, the MatchExpression is parsed incorrectly and will return extra results. In this example, the document with a equal to 1 is returned incorrectly:

> db.c.drop()
true
> db.c.insert({a: 1})
WriteResult({ "nInserted" : 1 })
> db.c.insert({a: 2})
WriteResult({ "nInserted" : 1 })
> db.c.find({$jsonSchema: {}, a: 2})
{ "_id" : ObjectId("59b6fbbfd29495ce436648f2"), "a" : 1 }
{ "_id" : ObjectId("59b6fbc0d29495ce436648f3"), "a" : 2 }

This was introduced during development of the JSON Schema project, and therefore does not affect any stable version of the server.



 Comments   
Comment by Ramon Fernandez Marina [ 12/Sep/17 ]

Author:

{'username': u'dstorch', 'name': u'David Storch', 'email': u'david.storch@10gen.com'}

Message:SERVER-31042 Fix MatchExpression parser bug which causes predicates to be discarded.
Branch:master
https://github.com/mongodb/mongo/commit/27471dc703ea0144ce4419d0bb59a4d092877d24

Generated at Thu Feb 08 04:25:49 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.