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

Document(s) not found for class %{klass} with id(s) %{missin

Error message

Document(s) not found for class %{klass} with id(s) %{missing}.

What it means

Error "Document(s) not found for class %{klass} with id(s) %{missing}." thrown in mongodb/mongoid.

Source

Thrown at lib/mongoid/reloadable.rb:69

      reload_relations
    end

    # Checks to see if the given attributes argument indicates that the object
    # has been deleted. If the attributes are nil or an empty Hash, then
    # we assume it has been deleted.
    #
    # If Mongoid.raise_not_found_error is false, this will do nothing.
    #
    # @param [ Hash | nil ] attributes The attributes hash retrieved from
    #   the database
    #
    # @raise [ Errors::DocumentNotFound ] If the document was deleted.
    def check_for_deleted_document!(attributes)
      return unless Mongoid.raise_not_found_error
      return unless attributes.nil? || attributes.empty?

      shard_keys = atomic_selector.with_indifferent_access.slice(*shard_key_fields, :_id)
      raise Errors::DocumentNotFound.new(self.class, _id, shard_keys)
    end

    # Reload the document, determining if it's embedded or not and what
    # behavior to use.
    #
    # @example Reload the document.
    #   document._reload
    #
    # @return [ Hash ] The reloaded attributes.
    def _reload
      embedded? ? reload_embedded_document : reload_root_document
    end

    # Reload the root document.
    #
    # @example Reload the document.
    #   document.reload_root_document
    #

View on GitHub (pinned to 0da0e23d71)

When it happens

Trigger: Thrown at lib/mongoid/reloadable.rb:69 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/8f657ee53486ca4d. Report an issue: GitHub.