MongoEngine / MongoEngine/mongoengine

Support server-side document validation

Open
#1,312 6 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement
Dominant language
Python
Stars
4.3k
Forks
1.2k
Avg merge
4h 41m
Merged PRs (30d)
11

Description

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 https://github.com/MongoEngine/mongoengine/issues/1287)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading MongoEngine's existing index creation and management behavior, then review MongoDB's document validation documentation and the update method context mentioned in the issue. Done means MongoEngine can create and manage validators derived from document fields, with server-side validation enforced for direct access and updates.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, python
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.