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 tomongoc_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 withbson_mem_set_vtable(). if this function is called beforebson_mem_set_vtable(), thenbson_mem_restore_vtable()must be called before callingmongoc_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 π«Ά
πΈ COPYRIGHT πΈ
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
- epel 10: mongo-c-driver-devel 2.5.6-1.el10_3 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms