mongodb/mongoid · error
MONGOID: #{model} has shard config but is not persisted in a
Error message
MONGOID: #{model} has shard config but is not persisted in a sharded cluster: #{model.collection.cluster.summary} What it means
Error "MONGOID: #{model} has shard config but is not persisted in a sharded cluster: #{model.collection.cluster.summary}" thrown in mongodb/mongoid.
Source
Thrown at lib/mongoid/tasks/database.rb:184
# 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).
begin
model.collection.database.command(collStats: model.collection.name).first
rescue Mongo::Error::OperationFailure => e
# Code 26 is database does not exist.
# Code 8 is collection does not exist, as of 4.0.View on GitHub (pinned to 0da0e23d71)
When it happens
Trigger: Thrown at lib/mongoid/tasks/database.rb:184 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/bd41360813ff356e.
Report an issue: GitHub.