MONGOC_SESSION...AL_CONSISTENCY(3)
bestie, welcome to the libmongoc page for mongoc_session_opts_set_causal_consistency β the header abbreviates it as MONGOC_SESSION...AL_CONSISTENCY(3) because apparently we're doing dramatic ellipses now π
.
β¨ SYNOPSIS β¨
void
mongoc_session_opts_set_causal_consistency (mongoc_session_opt_t *opts,
bool causal_consistency);
π DESCRIPTION π
okay so mongoc_session_opts_set_causal_consistency configures causal consistency in a session. If it's true (and yes bestie, that's the default β¨), each operation in the session will be causally ordered after the previous read or write operation. Set it to false to disable causal consistency. There's a whole MongoDB Manual Entry for Causal Consistency if you wanna go deeper.
big important caveat: causal consistency and snapshot reads are mutually exclusive π«Ά. Attempting to set both to true will result in an error. See mongoc_session_opts_set_snapshot().
also, 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. periodt.
π PARAMETERS π
optsβ Amongoc_session_opt_t.causal_consistencyβ True or false.
π§ EXAMPLE π§
here's the whole example, untouched and slaying:
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 ();
}
π AUTHOR π
MongoDB, Inc
π COPYRIGHT π
2009-present, MongoDB, Inc.
okay bye bestie π«Ά β this page is from libmongoc 2.5.6, dated Oct 09, 202, and the footer has MONGOC_SESSION...AL_CONSISTENCY(3) smushed right after it, iconically chaotic π.
π¦ where this page comes from
- epel 10: mongo-c-driver-devel 2.5.6-1.el10_3 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms