[英]Connecting to a local MongoDB and MongoDB Atlas
I have a local app, that uses MongoDB Community Server, and I intend to deploy it to GCloud.我有一个本地应用程序,它使用 MongoDB 社区服务器,我打算将它部署到 GCloud。 I have also created a MongoDB Atlas DB, collection and document.
我还创建了一个 MongoDB Atlas 数据库、集合和文档。
How do I configure my local version to use Community Server and the production version to use Atlas?如何配置我的本地版本使用 Community Server 而生产版本使用 Atlas?
I've searched around, but I guess I don't know what to look for.我四处搜寻,但我想我不知道要寻找什么。
Secondly, is that the right method to go down?其次,这是 go 的正确方法吗?
You can use python configParser for this task.您可以使用 python configParser 来完成此任务。 Create a config.ini file as fillow.
创建一个 config.ini 文件作为填充。
[dev]
mongo_url = ...
[prod]
mongo_url = ...
In the file where you want to get the mongo url add following lines.在要获取 mongo url 的文件中添加以下行。
import configparser
import sys
config = configparser.ConfigParser()
config.read('config.ini')
version = sys.argv[0]
mongo_url = config[version].mongo_url
Then you can pass version (dev/prod) as a argument as follows.然后您可以将版本 (dev/prod) 作为参数传递,如下所示。
py app.py dev
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.