.\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "MONGOC_SESSION_OPTS_SET_SNAPSHOT" "3" "May 07, 2024" "1.27.1" "libmongoc" .SH SYNOPSIS .INDENT 0.0 .INDENT 3.5 .sp .EX void mongoc_session_opts_set_snapshot (mongoc_session_opt_t *opts, bool snapshot); .EE .UNINDENT .UNINDENT .sp Configure snapshot reads for a session. If true (false by default), each read operation in the session will be sent with a \(dqsnapshot\(dq level read concern. After the first read operation (\(dqfind\(dq, \(dqaggregate\(dq or \(dqdistinct\(dq), subsequent read operations will read from the same point in time as the first read operation. Set to true to enable snapshot reads. See \fI\%the official documentation for Read Concern \(dqsnapshot\(dq\fP\&. .sp Snapshot reads and causal consistency are mutually exclusive. Attempting to set both to true will result in an error. See \fI\%mongoc_session_opts_set_causal_consistency()\fP\&. .sp Snapshot reads can only be used on MongoDB server version 5.0 and later and cannot be used during a transaction. A write operation in a snapshot\-enabled session will also result in an error. .SH PARAMETERS .INDENT 0.0 .IP \(bu 2 \fBopts\fP: A \fI\%mongoc_session_opt_t\fP\&. .IP \(bu 2 \fBsnapshot\fP: True or false. .UNINDENT .SH EXAMPLE .INDENT 0.0 .INDENT 3.5 .sp .EX 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 (\(dqmongodb://example/?appname=session\-opts\-example\(dq); 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, \(dqFailed to start session: %s\en\(dq, error.message); abort (); } collection = mongoc_client_get_collection (client, \(dqtest\(dq, \(dqcollection\(dq); r = mongoc_client_session_append (client_session, &find_opts, &error); if (!r) { fprintf (stderr, \(dqmongoc_client_session_append failed: %s\en\(dq, 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); .EE .UNINDENT .UNINDENT .SH AUTHOR MongoDB, Inc .SH COPYRIGHT 2017-present, MongoDB, Inc .\" Generated by docutils manpage writer. .