2

i am using MongoDB(3.6) in Django(3.1.5) through djongo(1.3.3).

models.py

from djongo import models

class ModelClass(models.Model):
       name = models.CharField(max_length=250)
       is_active = models.BooleanField(default=True)

view.py

def model_class_view(request):
      obj = ModelClass.objects.get(name='name', is_active=True)

it is giving an error: DatabaseError No exception message supplied

Krishna Chaurasia
  • 8,924
  • 6
  • 22
  • 35
Lokesh sahu
  • 149
  • 1
  • 1
  • 8
  • Could you post the complete error message? – Razenstein Jan 23 '21 at 08:09
  • https://cdn.imageupload.workers.dev/fYYRzisu_MongoDBDatabaseError%20(1).png – Lokesh sahu Jan 23 '21 at 10:08
  • I have the exact same problem Did you find a solution? I also have a boolean that crashes my entire project. Working with the newest django version and MongoDB. Any help yet? Cheers PS same happens with all modifiers like `filter`, `exclude`, `get` etc – buchstabe Jul 30 '21 at 09:46

1 Answers1

3

I had a similar problem and it is caused by Djongo not being able to filter for boolean fields correctly.

An issue was raised here https://github.com/nesdis/djongo/issues/465 which also proposes a workaround. So instead of is_active=True make it is_active__in=[True]

So try this:

def model_class_view(request):
      obj = ModelClass.objects.get(name='name', is_active__in=[True])
Fahad Alduraibi
  • 372
  • 6
  • 17