MONGOC_COLLECT...NDEX_WITH_OPTS(3)

πŸ’– MONGOC_COLLECT...NDEX_WITH_OPTS(3) πŸ’–

okay bestie, so this one lives in libmongoc, and before you get attached β€” it's giving retired. Scroll down to the warning first, i promise it matters. πŸ™ˆ


🚨 WARNING 🚨

Deprecated since version 1.8.0. See Manage Collection Indexes for alternatives. no cap, this one's been in its flop era since 1.8.0 β€” go look at the alternatives instead. πŸ’…


✨ SYNOPSIS ✨

bool
mongoc_collection_create_index_with_opts (mongoc_collection_t *collection,
                                          const bson_t *keys,
                                          const mongoc_index_opt_t *index_opts,
                                          const bson_t *command_opts,
                                          bson_t *reply,
                                          bson_error_t *error);

πŸŽ€ PARAMETERS πŸŽ€

  • collection β€” a mongoc_collection_t. the main character, obviously. πŸ‘‘
  • keys β€” a bson_t. the key spec, serving looks.
  • index_opts β€” a mongoc_index_opt_t. all the ~aesthetic~ choices.
  • reply β€” a maybe-NULL pointer to overwritable storage for a bson_t that's gonna hold the results. note the maybe-NULL bestie, it's flexible like that. πŸ¦‹
  • error β€” an optional spot for a bson_error_t, or NULL if you're feeling unbothered. πŸ“

command_opts may be NULL, or a BSON document with extra command options β€” literally only two vibes allowed here:

  • writeConcern β€” construct a mongoc_write_concern_t and use mongoc_write_concern_append() to add the write concern to opts. peek the example code for mongoc_client_write_command_with_opts() if you want the tea. β˜•
  • sessionId β€” first, construct a mongoc_client_session_t with mongoc_client_start_session(). 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 then use mongoc_client_session_append() to add the session to opts. example code for mongoc_client_session_t has the whole story. 🧚

🌸 DESCRIPTION 🌸

so this function will request the creation of a new index. that's the whole gig. πŸ’«

it does that by using the createIndexes command, and the server's reply gets stored in reply.

if no write concern is provided in command_opts, then the collection's write concern is what gets used. no write concern left behind. ✨

for all the options on creating indexes, go see mongoc_index_opt_t.


πŸ’€ ERRORS πŸ’€

errors are propagated via the error parameter. that's it, that's the whole section. straightforward fr fr.


🌈 RETURNS 🌈

returns true if successful. returns false and sets error if there are invalid arguments, or a server error, or a network error. 😭

reply is always initialized, and it must be destroyed with bson_destroy(). do not skip that, bestie, that's a leak waiting to happen. 🫢

if the server is running an obsolete version of MongoDB then reply may be empty β€” but it will still be initialized. empty but valid, it's giving minimalist. πŸ™ˆ


πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc

2009-present, MongoDB, Inc.


and that's the whole page, periodt. this little gem is from libmongoc, version 1.30.13, dated Oct 09, 202 β€” yes, that's the date stamp exactly as it came, i don't make the rules. πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«Ά

πŸ“¦ where this page comes from