Executing Schema Validation setup script is failing for a MongoDB collection

75 Views Asked by At

Executing Schema Validation setup script is failing for a MongoDB collection. Unable to configure the schema validator.

I am trying to add a Schema Validation to a MongoDB collection and facing the following error.

{
    "message" : "Document validators are not allowed on collection local.product with UUID b12596d5-3bc5-4321-94ef-ac006fb32abb in the local internal database",
    "ok" : 0,
    "code" : 72,
    "codeName" : "InvalidOptions"
}

This is the validator script that I am trying to execute, am I missing something here?

var validator={
    $jsonSchema : {
        bsonType : "object",
        additionalProperties : true,
        required : [ "productName" ],
        properties : {
            productName : {
                bsonType : "string",
                description : "must be a string and is required"
            }
        }
    }
};

db.runCommand( {
  collMod: "product",
  validator,
  validationLevel: "strict"
})
0

There are 0 best solutions below