Skip to content Skip to sidebar Skip to footer

Badyielderror When Using Find() Motor [mongodb + Tornado]

I am new to python tornado framework. I have a small collection of data in MongoDB. I am using a simple get function in my python file. I get a BadYieldError when using the db.coll

Solution 1:

find returns a MotorCursor. Yield the cursor's fetch_next property to advance the cursor and call next_object() to retrieve the 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 to the tutorial section Querying for More Than One Document for instructions on using Motor's find and MotorCursor.

Post a Comment for "Badyielderror When Using Find() Motor [mongodb + Tornado]"