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

Add transaction method

    • 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 documents and document classes. This method accepts a block, and all operation inside the block are wrapped in a mongodb transaction.

      Successful Transaction

      Person.transaction do
        # ...
      end
      

      will result in:

      • Client associated with the Person class starts a new session (see more about used clients below).
      • 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.

      Person.transaction do
        # ...
        raise SomeError
        # ...
      end
      

      will result in:

      • Client associated with the Person class 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: