Home:ALL Converter>Multiple JSON Schema validators per collection MongoDB

Multiple JSON Schema validators per collection MongoDB

Ask Time:2019-10-19T04:34:30         Author:gtbono

Json Formatter

In MongoDB, I can set up a JSON Schema validation in a collection I create, such as these:

db.createCollection("teste", {
    validator: {
        jsonSchema: {
            bsonType: "object",
            required: ["campo1", "numero1"],
            properties: {
                campo1: {
                    bsonType: "string",
                    description: "Deve ser uma string"
                },
                numero1: {
                    bsonType: "string",
                    description: "Deve ser um texto"
                },
            }
        }
    }
})

But I have mixed-type collections that make use of the Polymorphic Pattern. Where I have something like five or more "types" of schema that are accepted in a collection.

Can I setup multiple JSON Schema validators in a collection? or just one?

Author:gtbono,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58457833/multiple-json-schema-validators-per-collection-mongodb
yy