1MONGOC_SESSION_OPTS_SET_CAUSAL_CONMSOIlNSiGTbOEmCNo_CnSYgE(oS3cS)ION_OPTS_SET_CAUSAL_CONSISTENCY(3)
2
3
4

NAME

6       mongoc_session_opts_set_causal_consistency         -        mongoc_ses‐
7       sion_opts_set_causal_consistency()
8

SYNOPSIS

10          void
11          mongoc_session_opts_set_causal_consistency (mongoc_session_opt_t *opts,
12                                                      bool causal_consistency);
13
14       Configure causal consistency in a session. If true (the default),  each
15       operation  in  the  session will be causally ordered after the previous
16       read or write operation. Set to false to  disable  causal  consistency.
17       See the MongoDB Manual Entry for Causal Consistency.
18
19       Unacknowledged  writes  are  not  causally consistent. If you execute a
20       write operation with a mongoc_write_concern_t on which you have  called
21       mongoc_write_concern_set_w  with  a value of 0, the write does not par‐
22       ticipate in causal consistency.
23

PARAMETERS

25       · opts: A mongoc_session_opt_t.
26
27       · causal_consistency: True or false.
28

EXAMPLE

30          mongoc_client_t *client;
31          mongoc_session_opt_t *session_opts;
32          mongoc_client_session_t *client_session;
33          mongoc_collection_t *collection;
34          bson_t insert_opts = BSON_INITIALIZER;
35          bson_t *doc;
36          bson_error_t error;
37          bool r;
38
39          client = mongoc_client_new ("mongodb://example/?appname=session-opts-example");
40          mongoc_client_set_error_api (client, 2);
41
42          session_opts = mongoc_session_opts_new ();
43          mongoc_session_opts_set_causal_consistency (session_opts, false);
44          client_session = mongoc_client_start_session (client, session_opts, &error);
45          mongoc_session_opts_destroy (session_opts);
46
47          if (!client_session) {
48             fprintf (stderr, "Failed to start session: %s\n", error.message);
49             abort ();
50          }
51
52          collection = mongoc_client_get_collection (client, "test", "collection");
53          doc = BCON_NEW ("_id", BCON_INT32 (1));
54          r = mongoc_client_session_append (client_session, &insert_opts, NULL);
55          if (!r) {
56             fprintf (stderr, "mongoc_client_session_append failed: %s\n", error.message);
57             abort ();
58          }
59
60          r = mongoc_collection_insert_one (
61             collection, doc, &insert_opts, NULL /* reply */, &error);
62
63          if (!r) {
64             fprintf (stderr, "Insert failed: %s\n", error.message);
65             abort ();
66          }
67

AUTHOR

69       MongoDB, Inc
70
72       2017-present, MongoDB, Inc
73
74
75
76
771.16.2                           FMeObNG2O5C,_S2E0S2S0ION_OPTS_SET_CAUSAL_CONSISTENCY(3)
Impressum