def find_by(attrs = {})
      result = where(attrs).find_first
      if result.nil? && Mongoid.raise_not_found_error
        raise(Errors::DocumentNotFound.new(self, attrs))
      end
      yield(result) if result && block_given?
      result
    end
def find_by(attrs = {})
      result = where(attrs).find_first
      if result.nil? && Mongoid.raise_not_found_error
        raise(Errors::DocumentNotFound.new(self, attrs))
      end
      yield(result) if result && block_given?
      result
    end
Find the first +Document+ given the conditions.
 If a matching Document is not found and
 Mongoid.raise_not_found_error is true it raises
 Mongoid::Errors::DocumentNotFound, return null nil elsewise.

 @example Find the document by attribute other than id
   Person.find_by(:username => "superuser")

 @param [ Hash ] attrs The attributes to check.

 @raise [ Errors::DocumentNotFound ] If no document found
 and Mongoid.raise_not_found_error is true.

 @return [ Document, nil ] A matching document.

 @since 3.0.0