[SERVER-30988] Misleading error message when attempting to use $jsonSchema in aggregation Created: 07/Sep/17  Updated: 30/Oct/23  Resolved: 12/Sep/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: David Storch Assignee: Justin Seyster
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-09-11, Query 2017-10-02
Participants:

 Description   

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".



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

Author:

{'username': u'jseyster', 'name': u'Justin Seyster', 'email': u'justin.seyster@mongodb.com'}

Message:SERVER-30988 Fix misleading $jsonSchema error.

My original implementation of the $jsonSchema ban included a Status
error messaged that assumed the only reason to disallow $jsonSchema is
because of a featureCompatibilityVersion < 3.6. That assumption will
not be true, so this patch replaces that error with a generic
error. Code paths that include the $jsonSchema check because of the
featureCompatibilityVersion now rewrites this generic error with an
error that includes a link to the relevant documentation.

There is a ticket open to enable $jsonSchema in more places:
SERVER-30987.
Branch:master
https://github.com/mongodb/mongo/commit/c5e038cb5e25cfdd4037534d34ce0d4e11f5c1ec

Comment by Asya Kamsky [ 09/Sep/17 ]

Never mind, I see SERVER-30987

Comment by Asya Kamsky [ 09/Sep/17 ]

Why is $jsonSchema banned in simple $match?

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