Reputation: 756
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()})
Upvotes: 1
Views: 1256
Reputation: 2925
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":""}})
Upvotes: 1