Mongo.transaction

You're seeing just the function transaction, go back to Mongo module for more information.
Link to this function

transaction(topology_pid, fun, opts \\ [])

View Source

Convenient function for running multiple write commands in a transaction.

In case of TransientTransactionError or UnknownTransactionCommitResult the function will retry the whole transaction or the commit of the transaction. You can specify a timeout (:transaction_retry_timeout_s) to limit the time of repeating. The default value is 120 seconds. If you don't wait so long, you call with_transaction with the option transaction_retry_timeout_s: 10. In this case after 10 seconds of retrying, the function will return an error.

Example

{:ok, ids} = Mongo.transaction(top, fn ->
{:ok, %InsertOneResult{:inserted_id => id1}} = Mongo.insert_one(top, "dogs", %{name: "Greta"})
{:ok, %InsertOneResult{:inserted_id => id2}} = Mongo.insert_one(top, "dogs", %{name: "Waldo"})
{:ok, %InsertOneResult{:inserted_id => id3}} = Mongo.insert_one(top, "dogs", %{name: "Tom"})
{:ok, [id1, id2, id3]}
end, transaction_retry_timeout_s: 10)

If transaction/3 is called inside another transaction, the function is simply executed, without wrapping the new transaction call in any way. If there is an error in the inner transaction and the error is rescued, or the inner transaction is aborted (abort_transaction/1), the whole outer transaction is aborted, guaranteeing nothing will be committed.