Skip to content

Support server-side document validation #1312

Open
@dpercy

Description

@dpercy

Starting with version 3.2, MongoDB supports document validation on the server: https://docs.mongodb.com/manual/core/document-validation/

It would be pretty cool if MongoEngine could create and manage the validator, similar to how it already creates and manages indexes. For example, if I have a class like

class Foo:
    name = StringField(required=True)
    x = IntegerField(min_value=1)

MongoEngine could create a validator like

db.runCommand( {
   collMod: "foo",
   validator: { name: {$type: "string"}, x: {$type: "number", $gte: 1} },
   validationLevel: "strict"
} )

This would be useful because:

  • if a developer or a script accesses the MongoDB server, bypassing MongoEngine, the server-side validation will still be enforced
  • if you use MongoEngine's update method, the server-side validation will still be enforced (this would partially address On update the model is not validated #1287)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions