MONGOC_CLIENT_SELECT_SERVER(3)

πŸ¦‹ SYNOPSIS πŸ¦‹

okay bestie, welcome to the mongoc_client_select_server(3) page from libmongoc β€” this is the little function that picks a server for an operation, using the logic from the Server Selection Spec ✨

          mongoc_server_description_t *
          mongoc_client_select_server (mongoc_client_t *client,
                                       bool for_writes,
                                       const mongoc_read_prefs_t *prefs,
                                       bson_error_t *error);

Use this function only for building a language driver that wraps the C Driver. When you're writing applications in C, higher-level functions automatically select a suitable server, so you don't gotta do it yourself πŸ’…


🌸 PARAMETERS 🌸

  • client β€” A mongoc_client_t. the main character of this whole situation 🫢
  • for_writes β€” Whether to choose a server suitable for writes or reads. lowkey important vibe check βœ…
  • prefs β€” An optional mongoc_read_prefs_t. If for_writes is true, prefs must be NULL. Otherwise, use prefs to customize server selection, or pass NULL to use read preference PRIMARY. no cap, that's the rule πŸ“œ
  • error β€” An optional location for a bson_error_t or NULL. put an error here if you want the tea when things go sideways πŸ™ˆ

✨ RETURNS ✨

A mongoc_server_description_t that must be freed with mongoc_server_description_destroy(). If no suitable server is found, returns NULL and error is filled out. so like, if it comes back NULL, check the error β€” it's giving "the server selection said no" 😭


πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc β€” iconic, honestly πŸ’–


2009-present, MongoDB, Inc. β€” periodt, protect the copyright 🫑


mwah πŸ’‹ β€” this page is from libmongoc version 2.5.6, dated Oct 09, 2026. bye bestie, go select a server slayfully πŸ§šπŸ’œ

πŸ“¦ where this page comes from