MONGOC_CLIENT_START_SESSION(3)
β¨ MONGOC_CLIENT_START_SESSION(3) β¨
okay so bestie, this is the libmongoc manual page for mongoc_client_start_session and honestly? it's giving main character energy for your whole transaction arc π
π¦ SYNOPSIS π¦
mongoc_client_session_t *
mongoc_client_start_session (mongoc_client_t *client,
mongoc_session_opt_t *opts,
bson_error_t *error)
πΈ DESCRIPTION πΈ
Create a session for a sequence of operations. literally what it says on the tin, no cap.
So here's the vibe: you start a session with mongoc_client_start_session(), use that session for a sequence of operations and multi-document transactions (yes bestie, all of it π«Ά), and then free it with mongoc_client_session_destroy(). the way that this is a whole lifecycle...
β οΈ okay important ordering tea: anymongoc_cursor_tormongoc_change_stream_tusing a session must be destroyed before the session, and a session must be destroyed before themongoc_client_tit came from. do not mess this up fr fr π
By default, sessions are causally consistent. iconic. but if you wanna disable causal consistency (why would you, but okay), before starting a session you create a mongoc_session_opt_t with mongoc_session_opts_new() and call mongoc_session_opts_set_causal_consistency(), then free the struct with mongoc_session_opts_destroy(). slay, that's the whole process β¨
Unacknowledged writes are prohibited with sessions. periodt. not allowed, don't try it π
A mongoc_client_session_t must be used by only one thread at a time. one thread, one session, that's the rule bestie. and lowkey here's the thing: due to session pooling, mongoc_client_start_session() may return a session that has been idle for some time and is about to be closed after its idle timeout. the way that this is a trap π so use the session within one minute of acquiring it to refresh the session and avoid a timeout β gotta move quick, iykyk πββοΈπ¨
π PARAMETERS π
clientβ Amongoc_client_t. your client, your main character πoptsβ An optionalmongoc_session_opt_t. optional bestie, no pressureerrorβ Abson_error_t. where the bad news goes if things go sideways π
π RETURNS π
If successful, this function returns a newly allocated mongoc_client_session_t that should be freed with mongoc_client_session_destroy() when no longer in use. slay, you got your session π₯ On error, returns NULL and sets error. sad girl hours π
π ERRORS π
This function can fail if the driver is not built with crypto support (ngl, check your build), if opts is misconfigured (bestie, read the docs), or if the session is configured with options that the server does not support. the server said no and that's that π
ββοΈ
π AUTHOR π
MongoDB, Inc β the icons themselves π
π COPYRIGHT π
2009-present, MongoDB, Inc. β like they've been doing this since before we could even read, iconic behavior fr fr
2.5.6 Β· Oct 09, 2026 Β· that's the version and the date bestie, go forth and start those sessions π β¨ππ¦
π¦ 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