[SERVER-31496] MatchExpressionParser::parse() should not throw Created: 10/Oct/17  Updated: 30/Oct/23  Resolved: 11/Oct/17

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

Type: Bug Priority: Major - P3
Reporter: Tess Avitabile (Inactive) Assignee: Tess Avitabile (Inactive)
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
Steps To Reproduce:

mongos> db.c.insert([{_id: 0}, {_id: 1}])
BulkWriteResult({
	"writeErrors" : [ ],
	"writeConcernErrors" : [ ],
	"nInserted" : 2,
	"nUpserted" : 0,
	"nMatched" : 0,
	"nModified" : 0,
	"nRemoved" : 0,
	"upserted" : [ ]
})
mongos> db.c.find()
{ "_id" : 0 }
{ "_id" : 1 }
mongos> db.runCommand({delete: "c", deletes: [{q: {_id: 0}, limit: 1}, {q: {$bad: 1}, limit: 1}]})
{
	"ok" : 1,
	"n" : 1,
	"writeErrors" : [
		{
			"index" : 1,
			"code" : 2,
			"errmsg" : "Could not parse delete query { $bad: 1.0 } :: caused by :: BadValue: unknown top level operator: $bad"
		}
	],
	"$clusterTime" : {
		"clusterTime" : Timestamp(1507659631, 2),
		"signature" : {
			"hash" : BinData(0,"rw8JpFb2h+ZOg3uZFVLiHj0yGl8="),
			"keyId" : NumberLong("6475348091384889362")
		}
	},
	"operationTime" : Timestamp(1507659631, 2)
}
mongos> db.c.find()
{ "_id" : 1 }
mongos> db.c.drop()
true
mongos> db.c.insert([{_id: 0}, {_id: 1}])
BulkWriteResult({
	"writeErrors" : [ ],
	"writeConcernErrors" : [ ],
	"nInserted" : 2,
	"nUpserted" : 0,
	"nMatched" : 0,
	"nModified" : 0,
	"nRemoved" : 0,
	"upserted" : [ ]
})
mongos> db.runCommand({delete: "c", deletes: [{q: {_id: 0}, limit: 1}, {q: {$expr: "$$unbound"}, limit: 1}]})
{
	"ok" : 0,
	"errmsg" : "Use of undefined variable: unbound",
	"code" : 17276,
	"codeName" : "Location17276"
}
mongos> db.c.find()
{ "_id" : 0 }
{ "_id" : 1 }

Sprint: Query 2017-10-23
Participants:

 Description   

When we throw in MatchExpressionParser::parse() in a write on mongos, the behavior is different from when MatchExpressionParser::parse() returns a bad status. When we throw, the write returns ok:0, and none of the writes preceding the bad write are performed. When we return a bad status, the write returns ok:1 with a writeError, and any writes preceding the bad write are performed.

As a solution, MatchExpressionParser::parse() can catch DBException and turn it into a status.



 Comments   
Comment by Githook User [ 11/Oct/17 ]

Author:

{'email': 'tess.avitabile@mongodb.com', 'name': 'Tess Avitabile', 'username': 'tessavitabile'}

Message: SERVER-31496 MatchExpressionParser::parse() should not throw
Branch: master
https://github.com/mongodb/mongo/commit/b1d1b244c73a726c0c6708cf1cb196079f570414

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