我是 python 龙卷风框架的新手。我在 MongoDB 中有一小部分数据。我在 python 文件中使用一个简单的 get 函数。我得到一个BadYieldError
当使用db.collection.find()
选项。但db.collection.find_one()
工作正常,但它只显示一条记录。
import tornado
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()
self.write(json_util.dumps(doc))
错误是:
ornado.gen.BadYieldError:产生未知对象 MotorCursor()
find
返回一个MotorCursor
。产生光标的fetch_next
属性来前进光标并调用next_object()
检索当前文档:
@gen.coroutine
def do_find():
cursor = db.test_collection.find({'i': {'$lt': 5}})
while (yield cursor.fetch_next):
document = cursor.next_object()
print document
请参阅教程部分查询多个文档有关使用电机的说明find
and MotorCursor
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)