Placed calls to formatIds in try/catch blocks.

The call to ObjectID.createFromHexString(query._id) throws an exception if the _id property isn't a well formatted mongodb id.