mongoengine - Ignore extra fields for schema validation

前端 未结 4 727
轮回少年
轮回少年 2021-02-03 21:11

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 q

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-03 21:13

    You can extend from mon.DynamicDocument.

    class AF(mon.DynamicDocument):
      meta = {
        'collection': 'af'
      }
    user_id = mon.StringField(db_field='customer_user_id')
    

    You can see from the document. A Dynamic Document class is allowing flexible, expandable and uncontrolled schemas.

提交回复
热议问题