Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongoengine - Ignore extra fields for schema validation

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?

like image 704
Andrew Avatar asked Apr 07 '15 15:04

Andrew


People also ask

Does MongoDB support schema validation?

MongoDB uses a flexible schema model, which means that documents in a collection do not need to have the same fields or data types by default. Once you've established an application schema, you can use schema validation to ensure there are no unintended schema changes or improper data types.

How do I delete MongoEngine?

1.2. Deleting documents. To delete a document, call the delete() method. Note that this will only work if the document exists in the database and has a valid id .


1 Answers

For ignoring this error when having extra fields while data loading, set strict to False in your meta dictionary.

class User(Document):     email = StringField(required=True, unique=True)     password = StringField()     meta = {'strict': False} 
like image 142
toto11 Avatar answered Oct 01 '22 06:10

toto11