[Python] How to convert MotorLatentCommandCursor to list

Discussão em 'Python' iniciado por Stack, Julho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I use Motor driver of mongoDB in my django project and I have problem to convert my data(who comes from database as cursor) to list, here is my code:

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

    for d in await list(documents):
    print(d)


    and the Error:

    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)

    Continue reading...

Compartilhe esta Página