Skip to content

Commit

Permalink
支持MONGO_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris-code committed Apr 28, 2024
1 parent c886177 commit c8b629b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
23 changes: 13 additions & 10 deletions feapder/db/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
1 change: 1 addition & 0 deletions feapder/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
1 change: 1 addition & 0 deletions feapder/templates/project_template/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit c8b629b

Please sign in to comment.