1

I am using django-mongodb engine for a django app that have multiple databases. Lets say I have a model named as Profiles. For selecting model values from correct db, I query it liked Profiles.objects.using(db_name). There are two cases for catching exceptions here. a) Db does not exists. b) Collection in that db does not exists for this model. Some exception at the time of db creation can lead to this state.

What is the best way to handle exceptions in case of these two conditions. I need to catch both exceptions separately to log different messages.

Dania
  • 1,007
  • 1
  • 14
  • 21
  • Are you asking how to catch two exceptions, or what are the specific exceptions to catch from mongodb? – Burhan Khalid Jan 09 '17 at 06:48
  • @BurhanKhalid Thanks for your comment. I want to know what are the specific exceptions to catch from mongodb in this case. – Dania Jan 09 '17 at 06:50
  • 1
    The easiest way to know is to do the operation and look at the traceback to see what exception is raised and then catch it; alternatively you can find a list of exceptions [at the documentation](http://api.mongodb.com/python/current/api/pymongo/errors.html). – Burhan Khalid Jan 09 '17 at 06:56

0 Answers0