---
name: "mongoc_session_opts_set_default_transaction_opts"
section: "3"
platform: "linux"
package: "libmongoc-doc"
version: "1.30.4-1+deb13u3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mongoc_session_opts_set_default_transaction_opts"
---

# mongoc\_session\_opts\_set\_default\_transaction\_opts(3)

## SYNOPSIS

```
void
mongoc_session_opts_set_default_transaction_opts (
   mongoc_session_opt_t *opts, const mongoc_transaction_opt_t *txn_opts);
```

Set the default options for transactions started with this session. The **txn\_opts** argument is copied and can be freed after calling this function.

When a session is first created with *mongoc\_client\_start\_session()*, it inherits from the client the read concern, write concern, and read preference with which to start transactions. Each of these fields can be overridden independently. Create a *mongoc\_transaction\_opt\_t* with *mongoc\_transaction\_opts\_new()*, and pass a non-NULL option to any of the *mongoc\_transaction\_opt\_t* setter functions:

- •

  *mongoc\_transaction\_opts\_set\_read\_concern()*

- •

  *mongoc\_transaction\_opts\_set\_write\_concern()*

- •

  *mongoc\_transaction\_opts\_set\_read\_prefs()*

Pass the resulting transaction options to *mongoc\_session\_opts\_set\_default\_transaction\_opts()*. Each field set in the transaction options overrides the inherited client configuration. There is an opportunity to override each one of these fields again by passing a *mongoc\_transaction\_opt\_t* to *mongoc\_client\_session\_start\_transaction()*.

## PARAMETERS

- •

  **opts**: A *mongoc\_session\_opt\_t*.

- •

  **txn\_opts**: A *mongoc\_transaction\_opt\_t*.

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
