diff --git a/feapder/db/mongodb.py b/feapder/db/mongodb.py index 1d8f1e7..099fee0 100644 --- a/feapder/db/mongodb.py +++ b/feapder/db/mongodb.py @@ -32,19 +32,22 @@ def __init__( url=None, **kwargs, ): + if not ip: + ip = setting.MONGO_IP + if not port: + port = setting.MONGO_PORT + if not db: + db = setting.MONGO_DB + if not user_name: + user_name = setting.MONGO_USER_NAME + if not user_pass: + user_pass = setting.MONGO_USER_PASS + if not url: + url = setting.MONGO_URL + if url: self.client = MongoClient(url, **kwargs) else: - if not ip: - ip = setting.MONGO_IP - if not port: - port = setting.MONGO_PORT - if not db: - db = setting.MONGO_DB - if not user_name: - user_name = setting.MONGO_USER_NAME - if not user_pass: - user_pass = setting.MONGO_USER_PASS self.client = MongoClient( host=ip, port=port, username=user_name, password=user_pass ) diff --git a/feapder/setting.py b/feapder/setting.py index 791373b..985709b 100644 --- a/feapder/setting.py +++ b/feapder/setting.py @@ -27,6 +27,7 @@ MONGO_DB = os.getenv("MONGO_DB") MONGO_USER_NAME = os.getenv("MONGO_USER_NAME") MONGO_USER_PASS = os.getenv("MONGO_USER_PASS") +MONGO_URL = os.getenv("MONGO_URL") # REDIS # ip:port 多个可写为列表或者逗号隔开 如 ip1:port1,ip2:port2 或 ["ip1:port1", "ip2:port2"] diff --git a/feapder/templates/project_template/setting.py b/feapder/templates/project_template/setting.py index 4edb55b..e09506b 100644 --- a/feapder/templates/project_template/setting.py +++ b/feapder/templates/project_template/setting.py @@ -16,6 +16,7 @@ # MONGO_DB = "" # MONGO_USER_NAME = "" # MONGO_USER_PASS = "" +# MONGO_URL = " # # # REDIS # # ip:port 多个可写为列表或者逗号隔开 如 ip1:port1,ip2:port2 或 ["ip1:port1", "ip2:port2"]