mongodb/mongoid · error · Mongoid::Errors::TransactionsNotSupported
transactions_not_supported
Error message
transactions_not_supported
What it means
Error "transactions_not_supported" thrown in mongodb/mongoid.
Source
Thrown at lib/mongoid/clients/sessions.rb:51
# 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.
#
# If the block does not raise an error, the transaction is committed.
# If an error is raised, the transaction is aborted. The error is passed on
# except for the `Mongoid::Errors::Rollback`. This error is not passed on,
# so you can raise is if you want to deliberately rollback the transaction.
#
# @param [ Hash ] options The transaction options. Please see the driverView on GitHub (pinned to 0da0e23d71)
When it happens
Trigger: Thrown at lib/mongoid/clients/sessions.rb:51 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/0891845e30135c3f.
Report an issue: GitHub.