Skip to content
Myr

update mongokit patterng

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jonathan Como · committed by Jonathan Como · parent 41b5d77 · Browse files · 1 file+5 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−2 removed

  • other:+5 added−2 removed

1 file+5 added−2 removed

modified:docs/patterns/mongokit.rst+5 added-2 removed
46 unmodified lines
47insert query to the next without any problem. MongoKit is just schemaless48too, but implements some validation to ensure data integrity.4950Here is an example document (put this also into :file:`app.py`, e.g.)::51 from mongokit import ValidationError5253 def max_length(length):54 def validate(value):55 if len(value) <= length:56 return True56 raise Exception('%s must be at most %s characters long' % length)57 raise ValidationError('%s must be at most {0} characters long'.format(length))58 return validate5960 class User(Document):61 structure = {
13 unmodified lines
757677This example shows you how to define your schema (named structure), a78validator for the maximum character length and uses a special MongoKit feature78called `use_dot_notation`. Per default MongoKit behaves like a python79called `use_dot_notation`. When you define a ValidationError, you can add the `%s`80into the format string to have the value placed in there for the final error message.81ValueErrors can also be thrown as an alternative. Per default MongoKit behaves like a python82dictionary but with `use_dot_notation` set to ``True`` you can use your83documents like you use models in nearly any other ORM by using dots to84separate between attributes.85
59 unmodified lines