MongoEngine / mongoengine

A Python Object-Document-Mapper for working with MongoDB
http://mongoengine.org
MIT License
4.24k stars 1.23k forks source link

Support server-side document validation #1312

Open dpercy opened 8 years ago

dpercy commented 8 years ago

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:

lafrech commented 8 years ago

Why not? Would you like to develop this?

dpercy commented 8 years ago

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 commented 8 years ago

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

lafrech commented 8 years ago

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

willyxiao commented 7 months ago

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

lafrech commented 7 months ago

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