mongoengine-忽略多余的字段以进行模式验证 [英] 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.
是否有一种方法可以忽略对mongoengine中的其他字段进行此模式验证?
Is there a way to ignore this schema validation for extra fields in mongoengine?
推荐答案
要在加载数据时有多余字段时忽略此错误,请在元字典中将strict
设置为False
.
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}
这篇关于mongoengine-忽略多余的字段以进行模式验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!