[COMPASS-2230] Default validation level and error not displayed properly Created: 27/Oct/17  Updated: 10/Jan/24  Resolved: 05/Mar/19

Status: Closed
Project: Compass
Component/s: Document Validation
Affects Version/s: 1.10.0
Fix Version/s: 1.18.0

Type: Bug Priority: Major - P3
Reporter: Raphael Londner Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mac OS X Sierra (10.12.4), MongoDB 3.6 RC1


Attachments: PNG File MongoDB_Compass_-_localhost_27017_test_testCol.png    
Issue Links:
Related

 Description   

After creating a new collection with a $jsonSchema validator, Compass doesn't display the default Document Validation action and level correctly, which makes updating the validator in Compass error-prone.

The default Document Validation action and error are respectively ERROR and STRICT, but Compass displays WARNING and OFF.



 Comments   
Comment by Raphael Londner [ 27/Oct/17 ]

This can be reproduced by creating the following validator in the mongo shell:

db.testCol.drop()
db.createCollection( "testCol",
{ 
    validator: 
       {
           $jsonSchema: 
        {
            bsonType: "object",
            required: ["b", "c", "d"],
            additionalProperties: false,
            properties: 
            {
            	_id: {},
                b: {
                  bsonType: "string",
                  description: "'b' must be a string and is required"
                },
                c: {
                  bsonType: ["double", "decimal"],
                  description: "'c' must be a double or a decimal and is required"
                },
                d: 
                {
                  bsonType: ["int", "string"],
                  pattern: "\\d",
                  minimum: 0,
                  maximum: 100,
                  exclusiveMaximum: true,
                  description: "'d' is a string that matches pattern, or a number in [0, 100) and is required"
                },
                e:{}
            }
        }
    }
}
)

Only after updating the validator with code such as the following would Compass display the validation action and level properly:

let validator = db.getCollectionInfos({name: "testCol"})[0].options.validator;
 
validator.$jsonSchema.required.push("e");
 
db.runCommand({
  "collMod": "testCol",
  "validator": validator
});

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