0

i am using Donjo for mongoDB for django. and getting error while fetching data from boolean field. settings.py

DATABASES = {
            'default': {
                   'ENGINE': 'djongo',
                   'NAME': 'seartzDB'
                 }
             }

model.py

class DynamicForm(models.Model):
    name = models.CharField(max_length=250)
    email = models.EmailField(max_length=250)
    is_email = models.BooleanField(default=False)
    ...

view.py

@api_view(['POST', ])
def get_form_view(request):
      email_data = DynamicForm.objects.filter(is_email=True)
      email_list = []
      for i in email_data:
            email_list.append(i.email)
      return Response({'data': email_list}, status=200)

urls.py

urlpatterns = [path('email/get/', get_form_view, name="get_form"),]

while i am fetching data from table with boolean field the it gives an error.

DatabaseError at /api/v1/blog/comment/create/3/
No exception message supplied
Request Method: POST
Request URL:    http://localhost:8000/api/v1/blog/comment/create/3/
Django Version: 3.1.4
Exception Type: DatabaseError
Exception Location: /home/singham/anaconda3/envs/pythonenv/lib/python3.8/site- 
packages/djongo/cursor.py, line 59, in execute
Python Executable:  /home/singham/anaconda3/envs/pythonenv/bin/python
Python Version: 3.8.5
Python Path:    
['/media/singham/e1e50bd4-08fa-4ffd-a015-a73c293eaafe/lepy- 
  backup/lokesh/seartz/mongodb/seartz',
  '/home/singham/anaconda3/envs/pythonenv/lib/python38.zip',
  '/home/singham/anaconda3/envs/pythonenv/lib/python3.8',
  '/home/singham/anaconda3/envs/pythonenv/lib/python3.8/lib-dynload',
  '/home/singham/anaconda3/envs/pythonenv/lib/python3.8/site-packages']
Server time:    Sat, 12 Dec 2020 13:00:40 +0000
5
  • can you tell me what django and mongo db version you are using Commented Dec 14, 2020 at 6:28
  • and what python version Commented Dec 14, 2020 at 6:29
  • python 3.8.5 and django 3.1.4 and MongoDB server version: 3.6.8 and djongo 1.3.3 for connect mongodb to django Commented Dec 14, 2020 at 12:45
  • github.com/lokeshsahu01/mongoDB.git here i have try somthing. Commented Dec 14, 2020 at 13:56
  • Brother you haven't called that djongo any where you are calling django.db everywhere but you are using djongo so how it works Commented Dec 14, 2020 at 14:31

2 Answers 2

1

For your error please refer docs because all codes have error so please reffer doc's as bellow link https://medium.com/@9cv9official/django-to-mongodb-djongo-or-mongoengine-d9d56b836a3d I hope it will helpful for you

 DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'blog',
'USER': 'root',
'PASSWORD': '******',
'HOST': '127.0.0.1',
'PORT': 3306,
}
Sign up to request clarification or add additional context in comments.

6 Comments

yes you are right, that is the think what i missed. thanks vishal , but in from djongo.models import forms is not exists and after this from djongo import models still getting DatabaseError from getting get query by boolean filed
Wait actually it may be django's problem because most of the time django does not support mongodb if you see django's docs it supports MySQL,sqlite and PostgreSQL
But I am trying to find out what problem you are getting
thanks for your efforts, i also trying to find from my side.
brother just try this edit it will set sever of database
|
1

I had the same problem a while back but I had found a way to overcome this problem.

email_data = DynamicForm.objects.filter(is_email__in = [True])

try this one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.