Reputation: 2398
Hi I have recently started programming in Python (I am newbie to python programming). I have a small collection of data in my MongoDB.I have written a simple get method to find all the data from my collection. But I have an error returning the fetched value.
Here is my code:
import bson
from bson import json_util
from bson.json_util import dumps
class TypeList(APIHandler):
@gen.coroutine
def get(self):
doc = yield db.vtype.find_one()
print(doc)
a = self.write(json_util.dumps(doc))
return a
def options(self):
pass
It gives me the fetched data.
But when I replace these lines
a = self.write....
return a
with return bson.json_util.dumps({ 'success': True, 'mycollectionKey': doc })
it gives me a type error.
TypeError: Expected None, got {'success': True, 'mycollectionKey': {'type': 1, 'item': 'cookie'}}
Can anyone explain me why I get this error and is there anyway to solve the problem.
Thanks in advance.
Upvotes: 0
Views: 311
Reputation: 22134
RequestHandler.get()
is not supposed to return anything. This error is simply warning you that you returned a value that is being ignored. Tornado handlers produce output by calling self.write(), not by returning a value.
Upvotes: 2