closeio/flask-mongorest

schemas folder

scheung38 opened this issue · 2 comments

Hi, I thought mongodB is schemaless? May I ask what is the use of schemas in this case? Thanks

Hi @scheung38 MongoDB is schemaless indeed. We can capitalize on that by having documents in the same collection with slightly different structures (e.g. by using a DictField or inheritance). That being said, you still want some level of validation on your fields. This is where schemas come in. MongoDB doesn't validate if you're inserting an integer, a string, or an email address in a given field's value, so instead you need your application to perform these checks.

You may be referring to schemas.py which is referencing cleancat schemas. This "schema" specifically validates incoming JSON from the HTTP API endpoints to ensure that user-provided data matches the schema that you do expect to store in Mongo.