1

How can I drop/delete a field from the document when it is already created using PyMoDM?

I have following model:

class User(MongoModel):
    email = fields.EmailField(required=True)
    password = fields.CharField(required=True)
    first_name = fields.CharField(required=True)
    last_name = fields.CharField(blank=True)

I have a user with all the fields. After deleting last_name from the model next "get" throws an error: ValueError: Unrecognized field name 'last_name'

user = User.objects.get({'email': email.lower()})
Evhz
  • 8,852
  • 9
  • 51
  • 69
Kristian
  • 738
  • 6
  • 15

1 Answers1

1

I found the same issue and understand this to be a bug. I have created an issue to help reslove it.

If you needed to remove all the last_name fields from your User collection you could use the underlying pymongo connection like so:

pymodm.connection._get_db()['user'].update_many({}, {"$unset":{"last_name":""}})
Steve Rossiter
  • 2,624
  • 21
  • 29