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

Having a root path assigned for

Error message

Having a root path assigned for %{klass} is invalid.

What it means

Atomic::Paths::Root#insert_modifier is only meaningful for embedded documents. Asking a root-path document for it means embedded-style atomic updates were attempted on a root document — usually after a mixed embedded/referenced mixup — so InvalidPath is raised.

Solutions

  1. Make the document embedded in a parent if embedded-style updates are intended
  2. Perform normal root-document persistence instead of atomic embedded modifiers
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/mongoid/atomic/paths/root.rb:29 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/a2605260758d9300. Report an issue: GitHub.

Appendix: source

Thrown at lib/mongoid/atomic/paths/root.rb:29

        # Create the new root path utility.
        #
        # @example Create the root path util.
        #   Root.new(document)
        #
        # @param [ Document ] document The document to generate the paths for.
        def initialize(document)
          @document, @path, @position = document, '', ''
        end

        # Asking for the insert modifier on a document with a root path
        # indicates a mixed association most likely happened.
        #
        # @example Attempt to get the insert modifier.
        #   root.insert_modifier
        #
        # @raise [ Errors::InvalidPath ] The error for the attempt.
        def insert_modifier
          raise Errors::InvalidPath.new(document.class)
        end
      end
    end
  end
end

View on GitHub (pinned to 0da0e23d71)