0

The basic problem is that in a Flask application trying to return a MongoDB document I get the error

TypeError: Object of type 'BaseQuerySet' is not JSON serializable

the get method is the following:

def get(self, projectId):

        response = MyObject.objects(project=projectId)

        return response , 200, None

There may be multiple objects with the same projectId so a BaseQuerySet is returned.

I tried using BSON json_util (as suggested here: JSON serializing Mongodb) but the code below:

response=bson.json_util.dumps(response)

returns just the list of the document's fields without any value.

The only workaround I figure is to return a naive string concatenation of the fields I need. The same code was working fine few time ago, have anyone got a similar problem?

EDIT

The Class MyObject is like to the one below:

from flask_mongoengine import MongoEngine
from mongoengine.fields import *
db = MongoEngine()

class User(db.Document):

    email = db.StringField(max_length=120)
    project = db.StringField(db.StringField(max_length=64))
    creation_date = db.DateTimeField(default=datetime.datetime.now)
    modified_date = db.DateTimeField(default=datetime.datetime.now)
Gianfranco
  • 199
  • 1
  • 6

0 Answers0