简体   繁体   中英

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. I have also created a MongoDB Atlas DB, collection and document.

How do I configure my local version to use Community Server and the production version to use 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?

You can use python configParser for this task. Create a config.ini file as fillow.

[dev]
mongo_url = ...        
          
[prod]
mongo_url = ...

In the file where you want to get the mongo url add following lines.

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.

py app.py dev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM