mongoengine filter query not working

751 Views Asked by At

I've defined a Flavor Document much like the rest of my models, and recently added the is_archived field:

class Flavor(BaseDocument):
    is_archived = BooleanField(default=False)

In a python shell I can verify that my Documents do indeed have the field and are set to a Boolean:

for f in Flavor.objects.all():
    print f.is_archived, type(f.is_archived)

>> False <type 'bool>
>> False <type 'bool>
>> ...

But when I filter the query it returns only the documents I have created since adding the field.

Flavor.objects(is_archived=False)
Flavor.objects.filter(is_archived=False)

>> [<Flavor: newFlavor>]
>> [<Flavor: newFlavor>]

How can I update my old Documents to be collected by the filtered query?

1

There are 1 best solutions below

0
On BEST ANSWER

Just figured it out. Perfect example of how carefully framing the question leads naturally to the answer:

for f in Flavor.objects.all():
    f.update(set__is_archived=f.is_archived)