mongodb/mongoid · error · Mongoid::Errors::CreateCollectionFailure

Cannot create collection %{collection_name} with options %{c

Error message

Cannot create collection %{collection_name} with options %{collection_options}. The following error was raised: %{error}.

What it means

Error "Cannot create collection %{collection_name} with options %{collection_options}. The following error was raised: %{error}." thrown in mongodb/mongoid.

Source

Thrown at lib/mongoid/collection_configurable.rb:45

        if /^system\./.match?(collection_name)
          # We do not do anything with system collections.
          return
        end

        collection.drop if force
        if coll_options = collection.database.list_collections(filter: { name: collection_name.to_s }).first
          raise Errors::DropCollectionFailure.new(collection_name) if force

          logger.debug(
            "MONGOID: Collection '#{collection_name}' already exists " +
            "in database '#{database_name}' with options '#{coll_options}'."
          )

        else
          begin
            collection.database[collection_name, storage_options.fetch(:collection_options, {})].create
          rescue Mongo::Error::OperationFailure => e
            raise Errors::CreateCollectionFailure.new(
              collection_name,
              storage_options[:collection_options],
              e
            )
          end
        end
      end
    end
  end
end

View on GitHub (pinned to 0da0e23d71)

When it happens

Trigger: Thrown at lib/mongoid/collection_configurable.rb:45 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/e571e8c1b340be00. Report an issue: GitHub.