Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-31496

MatchExpressionParser::parse() should not throw

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.0-rc0
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • Fully Compatible
    • ALL
    • Hide
      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 }
      
      Show
      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 }
    • Query 2017-10-23

      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.

            Assignee:
            tess.avitabile@mongodb.com Tess Avitabile (Inactive)
            Reporter:
            tess.avitabile@mongodb.com Tess Avitabile (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: