BadYieldError when using find() Motor [MongoDB + Tornado]

后端 未结 1 1090
野的像风
野的像风 2021-01-16 07:36

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 wh

相关标签:
1条回答
  • 2021-01-16 08:19

    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.

    0 讨论(0)
提交回复
热议问题