{"record":{"id":"69fbd3839ae92dfa","repo":"mongodb/mongoid","slug":"mongoid-model-has-shard-config-but-is-embedded","errorCode":null,"errorMessage":"MONGOID: #{model} has shard config but is embedded","messagePattern":"MONGOID: #(.+?) has shard config but is embedded","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/mongoid/tasks/database.rb","lineNumber":179,"sourceCode":"        end\n      end\n\n      # Shard collections for models that declare shard keys.\n      #\n      # Returns the model classes that have had their collections sharded,\n      # including model classes whose collections had already been sharded\n      # prior to the invocation of this method.\n      #\n      # @example Shard all collections\n      #   Mongoid::Tasks::Database.shard_collections\n      #\n      # @return [ Array<Class> ] The sharded models\n      def shard_collections(models = ::Mongoid.models)\n        models.map do |model|\n          next if model.shard_config.nil?\n\n          if model.embedded? && !model.cyclic?\n            logger.warn(\"MONGOID: #{model} has shard config but is embedded\")\n            next\n          end\n\n          unless model.collection.cluster.sharded? || model.collection.cluster.load_balanced?\n            logger.warn(\"MONGOID: #{model} has shard config but is not persisted in a sharded cluster: #{model.collection.cluster.summary}\")\n            next\n          end\n\n          # Database of the collection must exist in order to run collStats.\n          # Depending on server version, the collection itself must also\n          # exist.\n          # MongoDB does not have a command to create the database; the best\n          # approximation of it is to create the collection we want.\n          # On older servers, creating a collection that already exists is\n          # an error.\n          # Additionally, 3.6 and potentially older servers do not provide\n          # the error code when they are asked to collStats a non-existent\n          # collection (https://jira.mongodb.org/browse/SERVER-50070).","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/tasks/database.rb#L161-L197","documentation":"Error \"MONGOID: #{model} has shard config but is embedded\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/tasks/database.rb:179 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0da0e23d71adfbad31128c18e5e2c8c301c6f7c4","analyzedAt":"2026-08-23T06:25:47.656Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}