MONGOC_URI_GE...ISM_PROPERTIES(3)

πŸ’… MONGOC_URI_GET_MECHANISM_PROPERTIES πŸ’…

okay bestie, so this is a page from libmongoc (that's the MongoDB C driver, iykyk) and it's all about one lil function: mongoc_uri_get_mechanism_properties. it's giving "short and sweet but read the fine print," fr fr.


✨ SYNOPSIS ✨

bool
mongoc_uri_get_mechanism_properties (const mongoc_uri_t *uri,
                                     bson_t *properties /* OUT */);

πŸŽ€ PARAMETERS πŸŽ€

  • uri: a mongoc_uri_t. that's the main character here.
  • properties: an uninitialized bson_t. yes, uninitialized. don't be out here pre-initializing it, that's not the vibe.

🌸 DESCRIPTION 🌸

so what does it actually do? it fetches the "authMechanismProperties" options that were set on this mongoc_uri_t. simple as that, no cap.

now for the part you cannot skip (lowkey the most important bit):

the out-parameter properties should be an uninitialized, stack-allocated bson_t. it gets statically initialized with bson_init_static() so it points at the internal data of uri. that means: do not modify its contents πŸ™ˆ, and it becomes invalid after uri is destroyed. it's a borrowed pointer situation, bestie β€” not a copy. treat it like you're borrowing your friend's hoodie, not keeping it.

⭐ RETURNS ⭐

if no "authMechanismProperties" have been set on uri, the function returns false and properties remains uninitialized. so like… check the return value before you go touching properties, obviously. πŸ’€


πŸ”₯ EXAMPLE πŸ”₯

here's the whole thing in action, chef's kiss:

mongoc_uri_t *uri;
bson_t props;

uri = mongoc_uri_new (
   "mongodb://user%40DOMAIN.COM:password@localhost/?authMechanism=GSSAPI"
   "&authMechanismProperties=SERVICE_NAME:other,CANONICALIZE_HOST_NAME:true");

if (mongoc_uri_get_mechanism_properties (uri, &props)) {
   char *json = bson_as_canonical_extended_json (&props, NULL);
   printf ("%s\n", json);
   bson_free (json);
} else {
   printf ("No authMechanismProperties.\n");
}

and this code produces the output β€” look at it go:

{ "SERVICE_NAME" : "other", "CANONICALIZE_HOST_NAME" : "true" }

ate. no crumbs. πŸ“


πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc


2009-present, MongoDB, Inc.


okay that's the whole page, you're officially educated 🧚✨ β€” this was libmongoc 2.5.6, dated Oct 09, 2026, and honestly? iconic. go forth and get those mechanism properties, bestie πŸ«ΆπŸ’–

πŸ“¦ where this page comes from