---
name: "mongoc_session_opt_t"
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_opt_t"
---

# mongoc\_session\_opt\_t(3)

```
#include <mongoc/mongoc.h>
typedef struct _mongoc_session_opt_t mongoc_session_opt_t;
```

## SYNOPSIS

Start a session with *mongoc\_client\_start\_session()*, use the session for a sequence of operations and multi-document transactions, then free it with *mongoc\_client\_session\_destroy()*. Any *mongoc\_cursor\_t* or *mongoc\_change\_stream\_t* using a session must be destroyed before the session, and a session must be destroyed before the *mongoc\_client\_t* it came from.

By default, sessions are *causally consistent*. To disable causal consistency, before starting a session create a *mongoc\_session\_opt\_t* with *mongoc\_session\_opts\_new()* and call *mongoc\_session\_opts\_set\_causal\_consistency()*, then free the struct with *mongoc\_session\_opts\_destroy()*.

Unacknowledged writes are prohibited with sessions.

A *mongoc\_client\_session\_t* must be used by only one thread at a time. Due to session pooling, *mongoc\_client\_start\_session()* may return a session that has been idle for some time and is about to be closed after its idle timeout. Use the session within one minute of acquiring it to refresh the session and avoid a timeout.

See the example code for *mongoc\_session\_opts\_set\_causal\_consistency()*.

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
