如何打印结果pymongo.cursor.Cursos文件反对?

2024-04-25 07:11:19 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我目前的代码:

from pymongo import MongoClient
client = MongoClient()
client = MongoClient('localhost', 27017)
db = client.local
collection = db.orderbook_update
orderbook = collection.find({
    "lastUpdated": {"$lt": ts}
}).sort("position",pymongo.DESCENDING).limit(1)
print(orderbook)

当我这样做的时候,我的印刷品(订单)会告诉我:<pymongo.cursor.Cursor object at 0x7ff7defef828> 如何打印结果以便使用?数据库中的json文件有三个主要组件:lastUpdated、asks和bids。 谢谢您!你知道吗


Tags: 代码fromimportltclientlocalhostdblocal
1条回答
网友
1楼 · 发布于 2024-04-25 07:11:19

所有python生成器/游标对象都可以通过“for”循环进行检索。你知道吗

#create  array object
order = []

for i in orderbook:
    print i
    order.append(i)
print order

您还可以:

order = list(orderbook)

注意:执行此操作后,光标对象将不可用

相关问题 更多 >