Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
a)I want to connect to MongoDB b)Surround Mondodb with try-catch block c)catch exceptions.

I have to use git to get the latest branch.

I have assumed that the below command will run before MongoDB connection:
source setenv.sh
source /opt/home/setenv.sh
python3 mongodb.py
python script should have a shell wrapper of the same name that sources the setenv.sh script under /opt/home/

shell wrapper name: mongodb.sh python script name: mongodb.py I have to use shell wrapper to run the script

coding env is jupyter lab, I don't know how to use it that's why I am asking this question here. Love to getting help

What I have tried:

I have used below code to connect with mongo:

from urllib.parse
import quote_plus
import os
import json from pymongo
import MongoClient
import SSL
def main():

environment = "Git" if os.environ.get('ENVIRONMENT_NAME') is None else os.environ.get('ENVIRONMENT_NAME')
config_directory = os.path.abspath(os.path.join(os.path.dirname(__file__)))
with open(os.path.join(config_directory, "report_config.json")) as f:
common_configuration = json.load(f)
#mongo_db = common_configuration['mongo_db_'+environment]
mongo_url, mongo_db_name= create_mongo_url_db()
#print("mongo_url:%s, mongo_db_name:%s" %(mongo_url,mongo_db_name))
# mongo_url = "mongodb://%s:%s@%s:%s" % (
# quote_plus(mongo_db['user_name']), quote_plus(mongo_db['password']),
# quote_plus(mongo_db['host']), quote_plus(mongo_db['port']))
#mongo_db_name= mongo_db['mongo_db_name']
collection_name= "workflow"
db = MongoClient(mongo_url, ssl=True, ssl_cert_reqs=ssl.CERT_NONE)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900