October 2018
Intermediate to advanced
332 pages
8h 9m
English
MongoEngine's method to define documents allows either flexibility or rigidity on a collection-by-collection basis. Inheriting from mongo.Document means that only the keys defined in the class can be saved to the database. Those keys defined in the class can be empty, but everything else will be ignored. On the other hand, if your class inherits mongo.DynamicDocument, then any extra fields that are set will be treated as DynamicField and will be saved with the document, as follows:
class Post(mongo.DynamicDocument): title = mongo.StringField(required=True, unique=True) text = mongo.StringField() ...
To show the extreme case (which is not recommended), the following class is perfectly valid; it has no required fields and ...