MONGOC_SESSION_OPTS_NEW(3)

πŸ’… MONGOC_SESSION_OPTS_NEW(3) πŸ’…

okay bestie, welcome to the libmongoc manual page for making a fresh session-options struct. this is the little setup object you use when you want to tweak session behavior before the session even starts. iconic behavior, honestly πŸŽ€

✨ SYNOPSIS ✨

mongoc_session_opt_t *
mongoc_session_opts_new (void);

so here's the whole lifecycle, and yes it matters: start a session with mongoc_client_start_session(), use that session for a sequence of operations and multi-document transactions, then free it with mongoc_client_session_destroy(). 🫢

tiny-but-huge order check: any mongoc_cursor_t or mongoc_change_stream_t that's using a session must be destroyed before the session, and a session must be destroyed before the mongoc_client_t it came from. no skipping the cleanup queue, bestie 😭

by default, sessions are causally consistent. to disable causal consistency, do it before starting a session: create a mongoc_session_opt_t with mongoc_session_opts_new(), call mongoc_session_opts_set_causal_consistency(), then free the struct with mongoc_session_opts_destroy(). slay, but in the correct order ✨

unacknowledged writes are prohibited with sessions. that's the rule, no cap πŸ’€

a mongoc_client_session_t must be used by only one thread at a time. and because of 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. use the session within one minute of acquiring it to refresh the session and avoid a timeout. literally set a timer if you have to ⏳

also: see the example code for mongoc_session_opts_set_causal_consistency(). iykyk πŸ’–

πŸ’– RETURNS πŸ’–

a new mongoc_session_opt_t β€” and it must be freed with mongoc_session_opts_destroy(). don't leave it hanging, bestie πŸŽ€

🫢 AUTHOR 🫢

MongoDB, Inc

2009-present, MongoDB, Inc.


kisses and clean teardown, this was libmongoc version 2.5.6, dated Oct 09, 2026, page MONGOC_SESSION_OPTS_NEW(3) πŸ’‹βœ¨

πŸ“¦ where this page comes from