|
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
|
});
|
|