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: any mongoc_cursor_t or mongoc_change_stream_t using a session must be destroyed before the session, and a session must be destroyed before the mongoc_client_t it 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 β€” A mongoc_client_t. your client, your main character 🌟
  • opts β€” An optional mongoc_session_opt_t. optional bestie, no pressure
  • error β€” A bson_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 πŸ’œ

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