I am doing MongoDB lookups by converting a string to BSON. Is there a way for me to determine if the string I have is a valid ObjectID for Mongo before doing the conversion?
If you have the hex string you can use this:
ObjectId.isValid(ObjectId.createFromHexString(hexId));