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

Misleading error message when attempting to use $jsonSchema in aggregation

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.0-rc0
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Fully Compatible
    • ALL
    • Query 2017-09-11, Query 2017-10-02

      The server can return an error message suggesting that FCV "3.6" must be set, despite the FCV already being set to "3.6":

      > db.adminCommand({setFeatureCompatibilityVersion: "3.6"})
      { "ok" : 1 }
      > db.c.aggregate([{$match: {$jsonSchema: {}}}])
      assert: command failed: {
      	"ok" : 0,
      	"errmsg" : "The featureCompatiblityVersion must be 3.6 to use $jsonSchema. See http://dochub.mongodb.org/core/3.6-feature-compatibility.",
      	"code" : 2,
      	"codeName" : "BadValue"
      } : aggregate failed
      _getErrorWithCode@src/mongo/shell/utils.js:25:13
      doassert@src/mongo/shell/assert.js:16:14
      assert.commandWorked@src/mongo/shell/assert.js:403:5
      DB.prototype._runAggregate@src/mongo/shell/db.js:257:9
      DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1285:12
      @(shell):1:1
      
      2017-09-07T13:09:57.953-0400 E QUERY    [thread1] Error: command failed: {
      	"ok" : 0,
      	"errmsg" : "The featureCompatiblityVersion must be 3.6 to use $jsonSchema. See http://dochub.mongodb.org/core/3.6-feature-compatibility.",
      	"code" : 2,
      	"codeName" : "BadValue"
      } : aggregate failed :
      _getErrorWithCode@src/mongo/shell/utils.js:25:13
      doassert@src/mongo/shell/assert.js:16:14
      assert.commandWorked@src/mongo/shell/assert.js:403:5
      DB.prototype._runAggregate@src/mongo/shell/db.js:257:9
      DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1285:12
      @(shell):1:1
      

      The problem is that this error message is currently returned for any caller of the match expression parser which bans JSON Schema:

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

      This error message, however, should be specific to the collMod and create collection call sites which have FCV-related checks. Other call sites which may ban JSON Schema should have a more general message like "$jsonSchema not allowed in this context".

            Assignee:
            justin.seyster@mongodb.com Justin Seyster
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: