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

MatchExpressionParser::parse() should not throw

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.6.0-rc0
    • Component/s: Querying
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Steps To Reproduce:
      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 }
    • Sprint:
      Query 2017-10-23

      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.

        Attachments

          Activity

            People

            Assignee:
            tess.avitabile Tess Avitabile
            Reporter:
            tess.avitabile Tess Avitabile
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: