There is not an easy/clean way to check if a string is a valid ObjectId.
I have implemented the method myself but it would be nice to have it (even if it's the way the Java driver does).
I have an API that receives ids that I have to use to find objects. Right now, I do MongoUtils.isValidId(object_id) but it would be good if I could do something like
if ObjectId.isValid(object_id):
doc =
result = db.col.find(doc)