i new python tornado framework. have small collection of data in mongodb. using simple function in python file. badyielderror when using db.collection.find() option. db.collection.find_one() works fine display 1 record.
import tornado import bson bson import json_util bson.json_util import dumps class typelist(apihandler): @gen.coroutine def get(self): doc = yield db.vtype.find() self.write(json_util.dumps(doc)) the error is:
tornado.gen.badyielderror: yielded unknown object motorcursor()
find returns motorcursor. yield cursor's fetch_next property advance cursor , call next_object() retrieve current document:
@gen.coroutine def do_find(): cursor = db.test_collection.find({'i': {'$lt': 5}}) while (yield cursor.fetch_next): document = cursor.next_object() print document please refer tutorial section querying more 1 document instructions on using motor's find , motorcursor.
Comments
Post a Comment