MONGOC_HANDSHAKE_DATA_APPEND(3)

πŸ’… MONGOC_HANDSHAKE_DATA_APPEND πŸ’…

okay so bestie, this one's from the libmongoc manual (the C Driver girlies, you know the ones) and honestly it's giving "little function, big feelings" energy. it's called mongoc_handshake_data_append and it's literally how you get your driver's name in the group chat that is the connection handshake. let's go πŸ’–


✨ SYNOPSIS ✨

bool
mongoc_handshake_data_append (const char *driver_name,
                              const char *driver_version,
                              const char *platform);

so this is the whole vibe: it appends the given strings to the handshake data for the underlying C Driver. that's it. that's the function 🫢


🌸 DESCRIPTION 🌸

okay so real talk: this function is intended for use by drivers which wrap the C Driver. so if you're one of those wrapper drivers, this is your moment to shine ✨

calling this function will store the given strings as handshake data about the system and driver, by appending them to the handshake data for the underlying C Driver. those values, along with all the other handshake data collected during mongoc_init, get sent to the server as part of the initial connection handshake in the "client" document. iykyk πŸ’…

NO CAP, READ THIS TWICE: this function must not be called more than once, and it also can't be called after server monitoring begins. periodt.

and when does server monitoring begin? okay so it depends:

  • for a single-threaded mongoc_client_t, server monitoring begins on the first operation requiring a server.
  • for a mongoc_client_pool_t, server monitoring begins on the first call to mongoc_client_pool_pop.

the passed-in strings are copied, so they don't have to remain valid after your call to mongoc_handshake_data_append(). that's a relief, honestly. but heads up: the driver may store truncated versions of the strings you passed in. πŸ™ˆ

⚠️ NOTE (the serious one, bestie): this function allocates memory, so caution should be used when using this in conjunction with bson_mem_set_vtable(). if this function is called before bson_mem_set_vtable(), then bson_mem_restore_vtable() must be called before calling mongoc_cleanup(). if you don't do that, memory gets freed by the wrong allocator and that is Not It πŸ’€. like, do not do that. fr fr.

πŸŽ€ PARAMETERS πŸŽ€

  • driver_name β€” an optional string storing the name of the wrapping driver. your name, bestie, put it out there πŸ’–
  • driver_version β€” an optional string storing the version of the wrapping driver. what era of you are we in 🌈
  • platform β€” an optional string storing any info about the current platform, for example configure options or compile flags 🧚

⭐ RETURNS ⭐

it returns true if the given fields are set successfully. otherwise it returns false and logs an error 😭 so check your return value, okay?

and here's the part where it gets cute. the default handshake data the driver sends with "hello" looks something like:

client: {
  driver: {
    name: "mongoc",
    version: "1.5.0"
  },
  os: {...},
  platform: "CC=gcc CFLAGS=-Wall -pedantic"
}

very "solo main character", very clean 😌

but then ✨ we ✨ enter ✨ the ✨ chat ✨. if we call mongoc_handshake_data_append() with ("phongo", "1.1.8", "CC=clang / ") and it returns true, the driver sends handshake data like:

client: {
  driver: {
    name: "mongoc / phongo",
    version: "1.5.0 / 1.1.8"
  },
  os: {...},
  platform: "CC=clang / gcc CFLAGS=-Wall -pedantic"
}

LOOK AT THAT SLASH. it's giving collab. it's giving "and my bestie". the way it just slots itself right in there πŸ₯ΉπŸ’… absolutely ate.


πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc β€” the icons themselves 🫢


2009-present, MongoDB, Inc. β€” protecting the whole squad since '09 πŸ’œ


and that's the page, bestie! 🌟 this was MONGOC_HANDSHAKE_DATA_APPEND(3) from the libmongoc manual, version 2.5.6, dated Oct 09, 2026 β€” mwah, go append some handshake data responsibly, and don't call it twice, i'm literally begging πŸ˜­πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from