mongodb/mongoid · error · Mongoid::Errors::ScopeOverwrite
Cannot create scope :%{scope_name}, because of existing meth
Error message
Cannot create scope :%{scope_name}, because of existing method %{model_name}.%{scope_name}. What it means
Error "Cannot create scope :%{scope_name}, because of existing method %{model_name}.%{scope_name}." thrown in mongodb/mongoid.
Source
Thrown at lib/mongoid/scopable.rb:244
Threaded.exit_without_default_scope(self)
end
private
# Warns or raises exception if overriding another scope or method.
#
# @api private
#
# @example Warn or raise error if name exists.
# Model.check_scope_name("test")
#
# @param [ String | Symbol ] name The name of the scope.
#
# @raise [ Errors::ScopeOverwrite ] If the name exists and configured to
# raise the error.
def check_scope_name(name)
return unless _declared_scopes[name] || respond_to?(name, true)
raise Errors::ScopeOverwrite.new(self.name, name) if Mongoid.scope_overwrite_exception
Mongoid.logger.warn(
"Creating scope :#{name} which conflicts with #{self.name}.#{name}. " +
"Calls to `Mongoid::Criteria##{name}` will delegate to " +
"`Mongoid::Criteria##{name}` for criteria with klass #{self.name} " +
'and will ignore the declared scope.'
)
end
# Checks if the intended scope is a valid object, either a criteria or
# proc with a criteria.
#
# @api private
#
# @example Check if the scope is valid.
# Model.check_scope_validity({})
#
# @param [ Object ] value The intended scope.View on GitHub (pinned to 0da0e23d71)
When it happens
Trigger: Thrown at lib/mongoid/scopable.rb:244 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of mongodb/mongoid@0da0e23d71 (2026-08-23).
Data as JSON: /api/errors/bc284e0c3f10e124.
Report an issue: GitHub.