[DOCS-10810] Docs for SERVER-30191: Add JSON Schema support for document validation Created: 20/Sep/17  Updated: 29/Oct/23  Resolved: 17/Oct/17

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: 3.6.0-rc0

Type: Task Priority: Major - P3
Reporter: Kay Kim (Inactive) Assignee: Pavithra Vetriselvan
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
documents SERVER-30191 Add JSON Schema support for document ... Closed
Participants:
Days since reply: 6 years, 17 weeks, 2 days ago
Epic Link: DOCS: 3.6 Server

 Description   

Documentation Request Summary:

We should 1) add mention of JSON Schema support in the release notes for 3.6, and 2) add a reference page for $jsonSchema.

The reference page should probably include the following:

  • The basic syntax of $jsonSchema.
  • Mention that we are supporting draft 4 of the JSON Schema spec, and links to the official spec.
  • A list of the JSON Schema draft 4 features that we do not support. This is available in the design document linked above.
  • A list of the extensions we have made to draft 4. Further information is available in the design document linked above, but I believe this just boils down to the addition of the bsonType keyword.
  • An example of setting up a document validator using $jsonSchema, which is the intended use case.
  • That featureCompatibilityVersion must be set to "3.6" or higher in order to use $jsonSchema in a document validator. Any such validator must be removed (either by dropping the collection or by collMod) before downgrading to version 3.4 of the server, otherwise a 3.4 server will fail to start up.

Engineering Ticket Description:

We will add support for JSON Schema via a new $jsonSchema operator in the match language. The following syntax can be used to create a collection with a JSON Schema specification as <schema>:

db.createCollection("myCollectionName", {validator: {$jsonSchema: <schema>}});

For example, the following creates a collection called stringsOnly in which the str field, if present, must be of type "string":

> db.stringsOnly.drop()
false
> db.createCollection("stringsOnly", {validator: {$jsonSchema: {properties: {str: {type: "string"}}}}});
{ "ok" : 1 }
> db.stringsOnly.insert({str: "foo"})
WriteResult({ "nInserted" : 1 })
> db.stringsOnly.insert({str: 1})
WriteResult({
	"nInserted" : 0,
	"writeError" : {
		"code" : 121,
		"errmsg" : "Document failed validation"
	}
})

We will support draft 4 of the JSON Schema spec, as described by https://tools.ietf.org/html/draft-zyp-json-schema-04 and https://tools.ietf.org/html/draft-fge-json-schema-validation-00. However, we cannot claim to be fully compliant with draft 4, since MongoDB's initial schema support will omit the following:

  • Hypermedia and linking properties of JSON Schema. The use of JSON References and JSON Pointers will not be supported.
  • Meta-validation of the schema specification via "$schema", a special JSON Schema-specific keyword that self-describes the schema itself. This keyword will be explicitly rejected, as opposed to silently ignored.
  • Semantic validation of strings via the "format" keyword.

We will support a few extensions to JSON schema which make sense for MongoDB. In particular, type validation will support not just number, integer, string, object, and array, but will also support the full list of BSON types.



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

Author:

{'email': 'pavi@MacBook-Pro-77.local', 'name': 'Pavithra Vetriselvan'}

Message: DOCS-10810 added new page for JSON schema support
Branch: master
https://github.com/mongodb/docs/commit/1a61fa8115f15e6a6eb26d31adae6d6c7087f45a

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