I want to verify that the objectID is a valid mongoID string.
Currently I have:
import bson try: bson.objectid.ObjectId(id) except: pass # do something
I wanted to make my exception more specific, and it looks like there is a solution, but
except bson.objectid.InvalidId ends up in
TypeError: id must be an instance of (str, unicode, ObjectId).
Ok, I tried to look further and found is_valid method but
bson.is_valid(1) results in another error
TypeError: BSON data must be an instance of a subclass of str.
So how can I properly check if my objectID is valid?