Support server-side document validation
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)
Why not? Would you like to develop this?
Would you like to develop this?
Maybe! It does interest me; maybe I'll take a crack at it. If somebody else wants to do it though, don't hold back on my account.
I tried running the test suite locally against MongoDB 3.2, but a handful of tests failed (it worked fine against MongoDB 2.6 though). There's an open issue about supporting 3.0 / having Travis run multiple mongod versions: https://github.com/MongoEngine/mongoengine/issues/861
@dpercy, I had issues running the tests locally last time I tried, and we couldn't figure out why.
Would you mind having a quick look at my test logs here, to see if you get the same tests failed?
Maybe it is a MongoDB version issue...
How's the progress on this feature @dpercy / @lafrech ?
Sorry, I'm not involved in MongoEngine development anymore.