mongoc_session_opts_set_causal_consistency()¶
Synopsis¶
void
mongoc_session_opts_set_causal_consistency (mongoc_session_opt_t *opts,
bool causal_consistency);
Configure causal consistency in a session. If true (the default), each operation in the session will be causally ordered after the previous read or write operation. Set to false to disable causal consistency. See the MongoDB Manual Entry for Causal Consistency.
Unacknowledged writes are not causally consistent. If you execute a write operation with a mongoc_write_concern_t on which you have called mongoc_write_concern_set_w() with a value of 0, the write does not participate in causal consistency.
Parameters¶
opts
: A mongoc_session_opt_t.causal_consistency
: True or false.
Example¶
mongoc_client_t *client;
mongoc_session_opt_t *session_opts;
mongoc_client_session_t *client_session;
mongoc_collection_t *collection;
bson_t insert_opts = BSON_INITIALIZER;
bson_t *doc;
bson_error_t error;
bool r;
client = mongoc_client_new ("mongodb://example/?appname=session-opts-example");
mongoc_client_set_error_api (client, 2);
session_opts = mongoc_session_opts_new ();
mongoc_session_opts_set_causal_consistency (session_opts, false);
client_session = mongoc_client_start_session (client, session_opts, &error);
mongoc_session_opts_destroy (session_opts);
if (!client_session) {
fprintf (stderr, "Failed to start session: %s\n", error.message);
abort ();
}
collection = mongoc_client_get_collection (client, "test", "collection");
doc = BCON_NEW ("_id", BCON_INT32 (1));
r = mongoc_client_session_append (client_session, &insert_opts, NULL);
if (!r) {
fprintf (stderr, "mongoc_client_session_append failed: %s\n", error.message);
abort ();
}
r = mongoc_collection_insert_one (
collection, doc, &insert_opts, NULL /* reply */, &error);
if (!r) {
fprintf (stderr, "Insert failed: %s\n", error.message);
abort ();
}
See Also:¶
mongoc_client_session_abort_transaction
mongoc_client_session_advance_cluster_time
mongoc_client_session_advance_operation_time
mongoc_client_session_commit_transaction
mongoc_client_session_get_client
mongoc_client_session_get_cluster_time
mongoc_client_session_get_lsid
mongoc_client_session_get_operation_time
mongoc_client_session_get_opts
mongoc_client_session_start_transaction
mongoc_session_opts_get_causal_consistency
mongoc_session_opts_get_default_transaction_opts
mongoc_session_opts_set_default_transaction_opts
mongoc_transaction_opts_destroy
mongoc_transaction_opts_get_max_commit_time_ms
mongoc_transaction_opts_get_read_concern
mongoc_transaction_opts_get_read_prefs
mongoc_transaction_opts_get_write_concern
mongoc_transaction_opts_set_max_commit_time_ms
mongoc_transaction_opts_set_read_concern