Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5534

Add transaction method to Mongoid module

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 9.0.0
    • Affects Version/s: None
    • Component/s: None
    • None

      Add transaction method to Mongoid module. This method accepts a block, and all operation inside the block are wrapped in a mongodb transaction.

      Successful Transaction

      Mongoid.transaction do
        # ...
      end
      

      will result in:

      • Default client starts a new session.
      • A transaction is started on the created session.
      • All the server commands issued by the code inside the block are sent with the session option.
      • When the block is completed, the transaction is committed.

      Failed Transaction
      Failed transaction means that the code inside the transaction block raises an exception.

      Mongoid.transaction do
        # ...
        raise SomeError
        # ...
      end
      

      will result in:

      • Default client starts a new session (see more about used clients below).

      NOTE
      Callbacks are not in the scope of this ticket.

      • A transaction is started on the created session.
      • All the server commands issued by the code inside the block before the exception are sent with the session option.
      • When the exception is raised, the transaction is aborted.

            Assignee:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Reporter:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: