First my django model was like this:
class List(Document):
owner = ReferenceField('User')
name = StringField()
users = ListField(ReferenceField('User'))
created_at = DateTimeField(default=datetime.datetime.now)
After I added a new filed is_cancelled and now it is like that:
class List(Document):
owner = ReferenceField('User')
name = StringField()
users = ListField(ReferenceField('User'))
created_at = DateTimeField(default=datetime.datetime.now)
is_cancelled = BooleanField(default = False)
I use mongoengine for django mongodb ORM. But now when i want to make a filter query:
List.objects.filter(is_cancelled=False)
returns []
I make all is_cancelled fields to False with django object:
for x in List.objects.all():
x.is_cancelled = False
x.save()
But I’m still getting an empty list for the query above.
I’m looking a django objects’ is_cancelled filed and I see is_cancelled = False
l = List.objects.all()[0]
l.is_cancelled
False
But when I look from mongodb shell. There is no filed as is_cancelled.
db.list.find()
{ "_cls" : "List", "_id" : ObjectId("4e8451598ebfa80228000000"), "_types" : [ "List" ],
"created_at" : ISODate("2011-09-29T16:24:28.781Z"), "name" : "listname", "users" : [
{
"$ref" : "user",
"$id" : ObjectId("4e79caf78ebfa80c00000001")
}, {
"$ref" : "user",
"$id" : ObjectId("4e79e4df8ebfa80b64000001")
}, {
"$ref" : "user",
"$id" : ObjectId("4e7aeb898ebfa80b64000001")
}, {
"$ref" : "user",
"$id" : ObjectId("4e79ce028ebfa80c00000004")
} ] }
How can I fix this query
Voila!
This is my answer:
https://github.com/hmarr/mongoengine/issues/282
There is a bug at the mongengine BooleanField with a value of False.
But they have fixed it with this patch:
https://github.com/hmarr/mongoengine/pull/283