Check for ObjectId validty before querying DB