I am trying to query my database. Some records currently have extra fields that are not included in my model schema (by error, but I want to handle these cases). When I try to query the DB and transform the records into the schema, I get the following error:
FieldDoesNotExist
The field 'X' does not exist on the document 'Y'
Because of the extra fields in the database that differ from the schema.
Is there a way to ignore this schema validation for extra fields in mongoengine?
You can extend from mon.DynamicDocument.
You can see from the document. A Dynamic Document class is allowing flexible, expandable and uncontrolled schemas.
I believe you want to use a DynamicDocument instead of a Document when defining your model and that will allow extra fields in the db schema to be ignored.
I think you want skip schema validation, so when you save your document
For ignoring this error when having extra fields while data loading, set
strict
toFalse
in your meta dictionary.