Thursday, February 8, 2024

MongoDB async queries

 1. Install Motor

pip install motor


2. create async client

import motor.motor_asyncio
mconn=motor.motor_asyncio.AsyncIOMotorClient(getMongoConnectionString())
db=mconn.db_name
coll= db.coll_name
find query:
mobjs = coll.find(..)
async for obj in mobhs

update call
await coll.update...

wait for long
await asyncio.wait_for(queue.join(), timeout=None)

No comments:

Post a Comment