Skip to content

Instantly share code, notes, and snippets.

@johnrichardrinehart
Created April 11, 2017 00:03
Show Gist options
  • Save johnrichardrinehart/7451e4d2c657c3f09030b77fa506a5d4 to your computer and use it in GitHub Desktop.
Save johnrichardrinehart/7451e4d2c657c3f09030b77fa506a5d4 to your computer and use it in GitHub Desktop.
import motor.motor_asyncio
import asyncio
client = motor.motor_asyncio.AsyncIOMotorClient('localhost', 27017)
db = client['testDB']
async def do_insert(user, collection_name):
document = {'user': user}
result = await db[collection_name].insert_one(document);
print('Added user %s' % user)
loop = asyncio.get_event_loop()
loop.run_until_complete(do_insert('john', 'testCollection'))
loop.run_until_complete(do_insert('maximo', 'testCollection'))
loop.run_until_complete(do_insert('phoenix', 'testCollection'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment