Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- import time
- from motor.motor_asyncio import AsyncIOMotorClient
- async def get_all_from_coll(col):
- client = AsyncIOMotorClient("localhost", 27017)
- db = client.project_matrix
- cursor = db[col].find()
- time.sleep(5)
- for document in await cursor.to_list(length=100):
- print(document)
- loop = asyncio.get_event_loop()
- print('001')
- loop.run_until_complete(get_all_from_coll('users'))
- print('002')
- >>>001
- >>>{'_id': ObjectId('58d9b178d011b53743d44413'), 'username': 'test1', 'password': 'test', '__v': 0}
- >>>{'_id': ObjectId('58d9b229d011b53743d44414'), 'username': 'test2', 'password': 'test', '__v': 0}
- >>>002
- for document in await cursor.to_list(length=100):
- # (wrong)
- async for document in cursor.limit(100):
- # (ok)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement