1MONGOC_CLIENT_START_SESSION(3) libmongoc MONGOC_CLIENT_START_SESSION(3)
2
3
4
6 mongoc_client_start_session - mongoc_client_start_session()
7
9 mongoc_client_session_t *
10 mongoc_client_start_session (mongoc_client_t *client,
11 mongoc_session_opt_t *opts,
12 bson_error_t *error)
13
14 Create a session for a sequence of operations.
15
16 Start a session with mongoc_client_start_session(), use the session for
17 a sequence of operations and multi-document transactions, then free it
18 with mongoc_client_session_destroy(). Any mongoc_cursor_t or
19 mongoc_change_stream_t using a session must be destroyed before the
20 session, and a session must be destroyed before the mongoc_client_t it
21 came from.
22
23 By default, sessions are causally consistent. To disable causal consis‐
24 tency, before starting a session create a mongoc_session_opt_t with
25 mongoc_session_opts_new() and call
26 mongoc_session_opts_set_causal_consistency(), then free the struct with
27 mongoc_session_opts_destroy().
28
29 Unacknowledged writes are prohibited with sessions.
30
31 A mongoc_client_session_t must be used by only one thread at a time.
32 Due to session pooling, mongoc_client_start_session() may return a ses‐
33 sion that has been idle for some time and is about to be closed after
34 its idle timeout. Use the session within one minute of acquiring it to
35 refresh the session and avoid a timeout.
36
38 • client: A mongoc_client_t.
39
40 • opts: An optional mongoc_session_opt_t.
41
42 • error: A bson_error_t.
43
45 If successful, this function returns a newly allocated
46 mongoc_client_session_t that should be freed with
47 mongoc_client_session_destroy() when no longer in use. On error, re‐
48 turns NULL and sets error.
49
51 This function can fail if the driver is not built with crypto support,
52 if opts is misconfigured, or if the session is configured with options
53 that the server does not support.
54
56 MongoDB, Inc
57
59 2017-present, MongoDB, Inc
60
61
62
63
641.23.1 Oct 20, 2022 MONGOC_CLIENT_START_SESSION(3)