{"record":{"id":"49a732844beb1f81","repo":"mongodb/mongoid","slug":"cannot-drop-collection-collection-name","errorCode":null,"errorMessage":"Cannot drop collection %{collection_name}.","messagePattern":"Cannot drop collection %(.+?)\\.","errorType":"exception","errorClass":"Mongoid::Errors::DropCollectionFailure","httpStatus":null,"severity":"error","filePath":"lib/mongoid/collection_configurable.rb","lineNumber":34,"sourceCode":"      # @param [ true | false ] force If true, the method will drop existing\n      #   collections before creating new ones. If false, the method will create\n      #   only new collection (that do not exist in the database).\n      #\n      # @raise [ Errors::CreateCollectionFailure ] If collection creation failed.\n      # @raise [ Errors::DropCollectionFailure ] If an attempt to drop collection failed.\n      def create_collection(force: false)\n        if collection_name.empty?\n          # This is most probably an anonymous class, we ignore them.\n          return\n        end\n        if /^system\\./.match?(collection_name)\n          # We do not do anything with system collections.\n          return\n        end\n\n        collection.drop if force\n        if coll_options = collection.database.list_collections(filter: { name: collection_name.to_s }).first\n          raise Errors::DropCollectionFailure.new(collection_name) if force\n\n          logger.debug(\n            \"MONGOID: Collection '#{collection_name}' already exists \" +\n            \"in database '#{database_name}' with options '#{coll_options}'.\"\n          )\n\n        else\n          begin\n            collection.database[collection_name, storage_options.fetch(:collection_options, {})].create\n          rescue Mongo::Error::OperationFailure => e\n            raise Errors::CreateCollectionFailure.new(\n              collection_name,\n              storage_options[:collection_options],\n              e\n            )\n          end\n        end\n      end","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/collection_configurable.rb#L16-L52","documentation":"Error \"Cannot drop collection %{collection_name}.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/collection_configurable.rb:34 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"}