mongodb/mongoid · error
MONGOID: #{model} has shard config but is embedded
Error message
MONGOID: #{model} has shard config but is embedded What it means
Error "MONGOID: #{model} has shard config but is embedded" thrown in mongodb/mongoid.
Source
Thrown at lib/mongoid/tasks/database.rb:179
end
end
# Shard collections for models that declare shard keys.
#
# Returns the model classes that have had their collections sharded,
# including model classes whose collections had already been sharded
# prior to the invocation of this method.
#
# @example Shard all collections
# Mongoid::Tasks::Database.shard_collections
#
# @return [ Array<Class> ] The sharded models
def shard_collections(models = ::Mongoid.models)
models.map do |model|
next if model.shard_config.nil?
if model.embedded? && !model.cyclic?
logger.warn("MONGOID: #{model} has shard config but is embedded")
next
end
unless model.collection.cluster.sharded? || model.collection.cluster.load_balanced?
logger.warn("MONGOID: #{model} has shard config but is not persisted in a sharded cluster: #{model.collection.cluster.summary}")
next
end
# Database of the collection must exist in order to run collStats.
# Depending on server version, the collection itself must also
# exist.
# MongoDB does not have a command to create the database; the best
# approximation of it is to create the collection we want.
# On older servers, creating a collection that already exists is
# an error.
# Additionally, 3.6 and potentially older servers do not provide
# the error code when they are asked to collStats a non-existent
# collection (https://jira.mongodb.org/browse/SERVER-50070).View on GitHub (pinned to 0da0e23d71)
When it happens
Trigger: Thrown at lib/mongoid/tasks/database.rb:179 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/69fbd3839ae92dfa.
Report an issue: GitHub.