Assuming that Venue is:
from mongoengine import *
from mongoengine_extras.fields import AutoSlugField
class Venue(Document):
name = StringField(required=True)
venue_slug = AutoSlugField()
I want to update all my venue_slug fields based on the name. I try:
for v in Venue.objects():
v(venue_slug = str(v.name)).update()
But I get:
v(venue_slug = str(v.name)).update()
TypeError: Error when calling the metaclass bases
'Venue' object is not callable
Is my update function correct? If you are not familiar with AutoSlugField()
could you write an example for a StringField()
update?
MongoEngine provides the following methods for atomic updates on a queryset. update_one() − Overwrites or adds first document matched by query. update() − Performs atomic update on fields matched by query. modify() − Update a document and return it.
On the Document Details page, click EDIT / UPDATE.
The following modifiers are available to update operations. For example - in db. collection. update() and db.
Your code incorrect. Try:
for v in Venue.objects():
v.update(set__venue_slug=str(v.name))
See documentation: http://docs.mongoengine.org/guide/querying.html#atomic-updates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With