mongoengine icon indicating copy to clipboard operation
mongoengine copied to clipboard

Support server-side document validation

Open dpercy opened this issue 9 years ago • 6 comments

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)

dpercy avatar Jun 14 '16 21:06 dpercy

Why not? Would you like to develop this?

lafrech avatar Jun 15 '16 07:06 lafrech

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.

dpercy avatar Jun 16 '16 02:06 dpercy

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 avatar Jun 16 '16 03:06 dpercy

@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...

lafrech avatar Jun 16 '16 10:06 lafrech

How's the progress on this feature @dpercy / @lafrech ?

willyxiao avatar Mar 07 '24 22:03 willyxiao

Sorry, I'm not involved in MongoEngine development anymore.

lafrech avatar Mar 08 '24 08:03 lafrech