MONGOC_CLIENT...R_DESCRIPTIONS(3)
π MONGOC_CLIENT...R_DESCRIPTIONS(3) π
okay bestie, welcome to libmongoc β this is the page for mongoc_client_get_server_descriptions and it's honestly such a main character function. it's giving "let me introduce you to everyone in the group chat" energy, except the group chat is your MongoDB topology. π¦
β¨ SYNOPSIS β¨
mongoc_server_description_t **
mongoc_client_get_server_descriptions (const mongoc_client_t *client,
size_t *n);
Fetches an array of mongoc_server_description_t structs for all known servers in the topology β like, every single one, no gatekeeping. π
Some receipts you need to know, no cap:
- it returns no servers until the client connects β so don't come for her before she's even linked up π
- it returns a single server if the client is directly connected
- it returns all members of a replica set</> if the client's MongoDB URI includes a
"replicaSet"option - it returns all known mongos servers if the MongoDB URI includes a list of them
and here's the cutest little example, show_servers, serving full tutorial realness π:
void
show_servers (const mongoc_client_t *client)
{
bson_t *b = BCON_NEW ("ping", BCON_INT32 (1));
bson_error_t error;
bool r;
mongoc_server_description_t **sds;
size_t i, n;
/* ensure client has connected */
r = mongoc_client_command_simple (client, "db", b, NULL, NULL, &error);
if (!r) {
MONGOC_ERROR ("could not connect: %s\n", error.message);
return;
}
sds = mongoc_client_get_server_descriptions (client, &n);
for (i = 0; i < n; ++i) {
printf ("%s\n", mongoc_server_description_host (sds[i])->host_and_port);
}
mongoc_server_descriptions_destroy_all (sds, n);
bson_destroy (&b);
}
πΈ PARAMETERS πΈ
clientβ amongoc_client_t. the client itself. the moment. the whole vibe. πnβ receives the length of the descriptions array. so she writes the count back out to you, bestie, you don't gotta count by hand π
π¦ RETURNS π¦
A newly allocated array β and yes, newly allocated means you own it now, it's your responsibility, no ghosting allowed π. You must free it with mongoc_server_descriptions_destroy_all().
fr fr do not skip the free. that's a memory leak and it's not iconic, it's just sad. π
β AUTHOR β
MongoDB, Inc β the ones who made all this happen, periodt. π«Ά
π COPYRIGHT π
2009-present, MongoDB, Inc.
okay that's the whole page, you ate that reading it tbh π β¨
~ cute little sign-off ~ this iconic dispatch came to you from libmongoc, version 2.5.6, dated Oct 09, 2026. go forth and fetch those server descriptions, bestie β slay responsibly π π
π¦ 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