MONGOC_SESSION...S_SET_SNAPSHOT(3)
π MONGOC_SESSION...S_SET_SNAPSHOT(3) π
okay so bestie, this is MONGOC_SESSION...S_SET_SNAPSHOT(3) from libmongoc β yes the name is a whole keyboard smash, but it's literally about setting snapshot reads on session options, and we're gonna make it make sense. πβ¨
β¨ SYNOPSIS β¨
void
mongoc_session_opts_set_snapshot (mongoc_session_opt_t *opts,
bool snapshot);
π DESCRIPTION π
This function configures snapshot reads for a session. If snapshot is true (the default is false, bestie), each read operation in the session will be sent with a "snapshot" level read concern. After the first read operation β "find", "aggregate", or "distinct" β subsequent read operations will read from the same point in time as the first read operation. Set snapshot to true to enable snapshot reads. The official documentation for Read Concern "snapshot" has the full lore. β¨
Snapshot reads and causal consistency are mutually exclusive. Attempting to set both to true will result in an error. See mongoc_session_opts_set_causal_consistency().
Important caveat, no cap: snapshot reads can only be used on MongoDB server version 5.0 and later, and they cannot be used during a transaction. A write operation in a snapshot-enabled session will also result in an error. π
π«Ά PARAMETERS π«Ά
optsβ Amongoc_session_opt_t.snapshotβ True or false.
πΈ EXAMPLE πΈ
Here's the full example, exactly as it appears β variables and all, bestie. Don't come for me about find_opts, okay? I'm just delivering the message π
.
mongoc_client_t *client;
mongoc_session_opt_t *session_opts;
mongoc_client_session_t *client_session;
mongoc_collection_t *collection;
bson_t query_opts = BSON_INITIALIZER;
bson_t filter = BSON_INITIALIZER;
bson_t pipeline = BSON_INITIALIZER;
client = mongoc_client_new ("mongodb://example/?appname=session-opts-example");
mongoc_client_set_error_api (client, MONGOC_ERROR_API_VERSION_2);
session_opts = mongoc_session_opts_new ();
mongoc_session_opts_set_snapshot (session_opts, true);
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");
r = mongoc_client_session_append (client_session, &find_opts, &error);
if (!r) {
fprintf (stderr, "mongoc_client_session_append failed: %s\n", error.message);
abort ();
}
/* First read operation will set the snapshot time for subsequent reads. */
cursor = mongoc_collection_find_with_opts (collection, filter, &query_opts, NULL);
/* Subsequent read operations will automatically read from the same point
* in time as the first read operation. */
cursor = mongoc_collection_aggregate (collection, MONGOC_QUERY_NONE, pipeline, &query_opts, NULL);
π AUTHOR π
MongoDB, Inc
π COPYRIGHT π
2009-present, MongoDB, Inc.
okay that's the whole page, bestie. Footer tea: libmongoc version 2.5.6, dated Oct 09, 202 β that's literally what the footer says π. Go forth and snapshot responsibly, periodt. πβ¨ππ¦
π¦ 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