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       Causal  consistency and snapshot reads are mutually exclusive. Attempt‐
20       ing to set both to true  will  result  in  an  error.  See  mongoc_ses‐
21       sion_opts_set_snapshot().
22
23       Unacknowledged  writes  are  not  causally consistent. If you execute a
24       write operation with a mongoc_write_concern_t on which you have  called
25       mongoc_write_concern_set_w  with  a value of 0, the write does not par‐
26       ticipate in causal consistency.
27

PARAMETERS

29opts: A mongoc_session_opt_t.
30
31causal_consistency: True or false.
32

EXAMPLE

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

AUTHOR

73       MongoDB, Inc
74
76       2017-present, MongoDB, Inc
77
78
79
80
811.21.1                           MMaOrNG0O2C,_S2E0S2S2ION_OPTS_SET_CAUSAL_CONSISTENCY(3)
Impressum