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 β€” A mongoc_client_t. your connection, your main character.
  • opts β€” A bson_t containing additional options. πŸŽ€
  • error β€” An optional location for a bson_error_t or NULL. (optional optional optional, iykyk)

opts may be NULL or a BSON document with additional command options:

  • sessionId β€” okay so first, construct a mongoc_client_session_t with mongoc_client_start_session(). Then you can begin a transaction with mongoc_client_session_start_transaction(), optionally with a mongoc_transaction_opt_t that overrides the options inherited from client, and use mongoc_client_session_append() to add the session to opts. See the example code for mongoc_client_session_t. πŸ¦‹
  • serverId β€” wanna target one specific server? include an int32 "serverId" field. you obtain the id by calling mongoc_client_select_server(), then mongoc_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 πŸ’–

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