Skip to content

Instantly share code, notes, and snippets.

@MwinyiMoha
Last active October 30, 2020 08:01
Show Gist options
  • Save MwinyiMoha/e862571d1eac6963368f21ec9aa25ed9 to your computer and use it in GitHub Desktop.
Save MwinyiMoha/e862571d1eac6963368f21ec9aa25ed9 to your computer and use it in GitHub Desktop.
from motor.motor_asyncio import AsyncIOMotorClient as AIOMC
DB_NAME = 'fastapi'
MONGO_URI = f"mongodb://<user>:<password>@localhost:27017/{DB_NAME}?authSource=admin"
todos_db = DB_NAME
todos_coll = 'todos'
class DB:
client: AIOMC = None
db = DB()
def connect_mongo():
db.client = AIOMC(MONGO_URI)
def disconnect_mongo():
db.client.close()
def get_database():
return db.client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment