小编Ami*_*ari的帖子

如何将 MotorLatentCommandCursor 转换为列表

我在我的 Django 项目中使用了 mongoDB 的 Motor 驱动程序,但在将我的数据(作为游标来自数据库的数据)转换为列表时遇到问题,这是我的代码:

documents = db.factor.aggregate([{"$limit": 3},
     {"$lookup": {"from": "subfactor", "localField": "_id", "foreignField": "factor_id", "as": "subfactor"}}])

for d in await list(documents):
    print(d)
Run Code Online (Sandbox Code Playgroud)

和错误:

File "/usr/lib/python3.8/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.8/asyncio/base_events.py", line 595, in run_until_complete
self.run_forever()
File "/usr/lib/python3.8/asyncio/base_events.py", line 563, in run_forever
self._run_once()
File "/usr/lib/python3.8/asyncio/base_events.py", line 1808, in _run_once
event_list = self._selector.select(timeout)
File "/usr/lib/python3.8/selectors.py", line 468, in select
fd_event_list = self._selector.poll(timeout, max_ev)
Run Code Online (Sandbox Code Playgroud)

python django mongodb motordriver python-3.x

2
推荐指数
1
解决办法
249
查看次数

标签 统计

django ×1

mongodb ×1

motordriver ×1

python ×1

python-3.x ×1