[COMPASS-4168] schema validation doesn't work Created: 25/Feb/20  Updated: 27/Oct/23  Resolved: 26/Feb/20

Status: Closed
Project: Compass
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: Eugene Kang Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Sprint: Iteration Yak

 Description   

compass version 1.20.5

When I enter the following into compass, I get a parsing error saying unexpected token ':'

$jsonSchema: {
  {
    bsonType: "object",
    required: ["name"],
    properties: {
      name: {
        bsonType: "string",
        description: "must be a string and is required"
      }
    }
  }
}

When I enter the following it saves the validator but the validator doesn't work because it doesn't have $jsonSchema notation.

  {
    bsonType: "object",
    required: ["name"],
    properties: {
      name: {
        bsonType: "string",
        description: "must be a string and is required"
      }
    }
  }

MongoDB Enterprise SHARED-DEMO-shard-0:PRIMARY> db.getCollectionInfos()
[
	{
		"name" : "schema_validation",
		"type" : "collection",
		"options" : {
			"validator" : {
				"bsonType" : "object",
				"required" : [
					"name"
				],
				"properties" : {
					"name" : {
						"bsonType" : "string",
						"description" : "must be a string and is required"
					}
				}
			},
			"validationLevel" : "strict",
			"validationAction" : "error"
		},
		"info" : {
			"readOnly" : false,
			"uuid" : UUID("7ff90c0b-0569-4974-8dff-d442d6bab910")
		},
		"idIndex" : {
			"v" : 2,
			"key" : {
				"_id" : 1
			},
			"name" : "_id_",
			"ns" : "kang.schema_validation"
		}
	},

When I manually create the collection using mdb clu with jsonSchema notation for the validator, it works.



 Comments   
Comment by Massimiliano Marcon [ 26/Feb/20 ]

The correct syntax in Compass is:

{
$jsonSchema: {
  {
    bsonType: "object",
    required: ["name"],
    properties: {
      name: {
        bsonType: "string",
        description: "must be a string and is required"
      }
    }
  }
}
}

Generated at Wed Feb 07 22:35:29 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.