You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
434 B
Python
19 lines
434 B
Python
import os
|
|
import re
|
|
|
|
from mongoengine import connect
|
|
|
|
MONGODB_URI = os.getenv('MONGODB_URI')
|
|
MONGO_RE = (r'mongodb://'
|
|
r'(?P<username>.+?)'
|
|
r':(?P<password>.+?)'
|
|
r'@(?P<host>(?:.+?):(?:\d+))'
|
|
r'/(?P<db>.+)')
|
|
|
|
if MONGODB_URI:
|
|
print(f"Connecting to {MONGODB_URI}")
|
|
connect_args = re.match(MONGO_RE, MONGODB_URI).groupdict()
|
|
connect(**connect_args)
|
|
else:
|
|
connect('matrix')
|