MONGOC_COLLECT...EXES_WITH_OPTS(3)

πŸ’… MONGOC_COLLECT...EXES_WITH_OPTS(3) ✨

okay bestie, so this is a page out of the libmongoc manual β€” yes, that libmongoc β€” and it's the one that tells you how to peek at all the indexes on a collection. buckle up, it's actually slay πŸŽ€


✨ SYNOPSIS ✨

mongoc_cursor_t *
mongoc_collection_find_indexes_with_opts (mongoc_collection_t *collection,
                                          const bson_t *opts);

so like, what does it even do? it fetches a cursor containing documents, and each of those documents corresponds to an index on this collection πŸ’– literally that's the whole vibe.

also important, no cap: this function is considered a retryable read operation. so when a transient error hits (think: a network error, errors due to replica set failover, etc.) the operation is safely retried once. and if retryreads is false in the URI (see mongoc_uri_t), the retry behavior does not apply. periodt. πŸ¦‹


🌸 PARAMETERS 🌸

  • collection β€” a mongoc_collection_t. the collection. the main character. πŸ‘‘
  • opts β€” a bson_t containing additional options.

and here's the thing, opts may be NULL, or it can be a BSON document with extra command options:

  • sessionId β€” 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 collection β€” and use mongoc_client_session_append() to add the session to opts. see the example code for mongoc_client_session_t 🫢
  • serverId β€” wanna target a specific server? include an int32 "serverId" field. get that id by calling mongoc_client_select_server(), then mongoc_server_description_id() on its return value. iykyk πŸ’…

for a list of all the options, see the MongoDB Manual entry on the listIndexes command. go read it, it's giving reference material πŸ“š


😭 ERRORS 😭

use mongoc_cursor_error() on the returned cursor to check for errors. that's it, that's the whole section. simple, iconic.


🌈 RETURNS 🌈

this function returns a newly allocated mongoc_cursor_t that should be freed with mongoc_cursor_destroy() when it's no longer in use. and get this β€” the returned mongoc_cursor_t is never NULL, even on error. never ever. πŸ™ˆ

the user must call mongoc_cursor_next() on the returned mongoc_cursor_t to execute the initial command. like, it's not gonna just do it for you, bestie.

cursor errors can be checked with mongoc_cursor_error_document(). it always fills out the bson_error_t if an error occurred, and optionally includes a server reply document if the error occurred server-side. thoughtful queen behavior ✨

WARNING: ⚠️ failure to handle the result of this function is a programming error. not "oopsie" β€” a programming error. handle your results, babe. πŸ’€

in the returned cursor, each result corresponds to the server's representation of an index on this collection. and if the collection does not exist on the server, the cursor will be empty. an empty cursor. a whole vibe check fail, but valid πŸ“

one more thing β€” the cursor functions mongoc_cursor_set_limit(), mongoc_cursor_set_batch_size(), and mongoc_cursor_set_max_await_time_ms() have no use on the returned cursor. don't call them here, they will not serve you. nope. 🧚

πŸ”₯ SEE ALSO πŸ”₯

Manage Collection Indexes.


πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc

2009-present, MongoDB, Inc.


so yeah, that's the whole page β€” libmongoc <rainbow>2.5.6</rainbow>, dated Oct 09, 2020, and this manual page is officially a wrap. go forth and find those indexes, bestie πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from