MONGOC_CLIENT_...AMES_WITH_OPTS(3)
π MONGOC_CLIENT_...AMES_WITH_OPTS(3) β the libmongoc one, bestie
okay so picture this: you're deep in libmongoc and you need to know what databases even exist on this server. this page is your girl. β¨
π«Ά SYNOPSIS
char **
mongoc_client_get_database_names_with_opts (mongoc_client_t *client,
const bson_t *opts,
bson_error_t *error);
This function queries the MongoDB server for a list of known databases. literally its whole job, and it eats. π
This function is considered a retryable read operation. so when a transient error happens β think a network error, errors due to replica set failover, etc. β the operation is safely retried once. cute, right? but heads up: if retryreads is false in the URI (go see mongoc_uri_t), that retry behavior does not apply. no retries for you. π
πΈ PARAMETERS
clientβ Amongoc_client_t. your connection, your main character.optsβ Abson_tcontaining additional options. πerrorβ An optional location for abson_error_torNULL. (optional optional optional, iykyk)
opts may be NULL or a BSON document with additional command options:
sessionIdβ okay so first, construct amongoc_client_session_twithmongoc_client_start_session(). Then you can begin a transaction withmongoc_client_session_start_transaction(), optionally with amongoc_transaction_opt_tthat overrides the options inherited fromclient, and usemongoc_client_session_append()to add the session toopts. See the example code formongoc_client_session_t. π¦serverIdβ wanna target one specific server? include anint32"serverId"field. you obtain the id by callingmongoc_client_select_server(), thenmongoc_server_description_id()on its return value. that's the pipeline, bestie. β
For a list of all the options, see the MongoDB Manual entry on the listDatabases command. (iconic documentation behavior, go read it π)
π ERRORS
Errors are propagated via the error parameter. that's the whole section. short and slaying.
π₯ RETURNS
A NULL terminated vector of NULL-byte terminated strings. that result should be freed with bson_strfreev(). please free it, do not just leave it there like a sad little leak π
NULL is returned upon failure and error is set.
π EXAMPLES
{
bson_error_t error;
char **strv;
unsigned i;
if ((strv = mongoc_client_get_database_names_with_opts (client, NULL, &error))) {
for (i = 0; strv[i]; i++)
printf ("%s\n", strv[i]);
bson_strfreev (strv);
} else {
fprintf (stderr, "Command failed: %s\n", error.message);
}
}
see how it prints every name and then frees? that's the vibe check passing. β
π AUTHOR
MongoDB, Inc π
π COPYRIGHT
2009-present, MongoDB, Inc.
okay that's the whole page, now go get those database names π§
this one's from libmongoc version 2.5.6, dated Oct 09, 202β¦ (the date got cut off in the source, not me being dramatic bestie). mwah π
π¦ 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