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

sessions_not_supported

Error message

sessions_not_supported

What it means

Error "sessions_not_supported" thrown in mongodb/mongoid.

Source

Thrown at lib/mongoid/clients/sessions.rb:45

        #   end
        #
        # @param [ Hash ] options The session options. Please see the driver
        #   documentation for the available session options.
        #
        # @raise [ Errors::InvalidSessionUse ] If an operation is attempted on a model using another
        #   client from which the session was started or if sessions are nested.
        #
        # @return [ Object ] The result of calling the block.
        #
        # @yieldparam [ Mongo::Session ] The session being used for the block.
        def with_session(options = {})
          raise Mongoid::Errors::InvalidSessionNesting.new if Threaded.get_session(client: persistence_context.client)

          session = persistence_context.client.start_session(options)
          Threaded.set_session(session, client: persistence_context.client)
          yield(session)
        rescue Mongo::Error::InvalidSession => e
          raise Mongoid::Errors::SessionsNotSupported.new if e.is_a?(Mongo::Error::SessionsNotSupported)

          raise e
        rescue Mongo::Error::OperationFailure => e
          if (e.code == 40_415 && e.server_message =~ /startTransaction/) ||
             (e.code == 20 && e.server_message =~ /Transaction/)
            raise Mongoid::Errors::TransactionsNotSupported.new
          else
            raise e
          end
        rescue *transactions_not_supported_exceptions
          raise Mongoid::Errors::TransactionsNotSupported
        ensure
          Threaded.clear_modified_documents(session)
          Threaded.clear_session(client: persistence_context.client)
        end

        # Executes a block within the context of a transaction.
        #

View on GitHub (pinned to 0da0e23d71)

When it happens

Trigger: Thrown at lib/mongoid/clients/sessions.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/6e9e9c1a273fb026. Report an issue: GitHub.