Fix duplicate error check
Depending on pymongo it might raise a TypeError or ValueError