High level practice for ignore exception for mongoDB in Python

167 views Asked by At

I'm using mongoDB to store error logs from my project, but the issues is that sometime mongoDB can not be connected or duplicated value and then throw the error make python process crash.

client = MongoClient()
mongodb = client[db]
class CollectionNames:
    Invoke = 'invoke'
md = 'error'
mongodb[CollectionNames.invoke].insert_one(md)

I can not write one by one try catch exeption for all pymongo built-in function insert_one or insert_all

try:
    mongodb[CollectionNames.Invoke].insert_one(md)
except:
    nothing()

how can I wrap insert_one before pymongo built-in function.

0

There are 0 answers