MONGOC_COLLECT...COMMAND_SIMPLE(3)

✨ SYNOPSIS ✨

okay bestie, welcome to the MONGOC_COLLECT...COMMAND_SIMPLE(3) page from the libmongoc manual 🫢 this is the function that runs a command on a collection, and the synopsis is literally:

          bool
          mongoc_collection_command_simple (mongoc_collection_t *collection,
                                            const bson_t *command,
                                            const mongoc_read_prefs_t *read_prefs,
                                            bson_t *reply,
                                            bson_error_t *error);

πŸŽ€ PARAMETERS πŸŽ€

  • collection β€” a mongoc_collection_t. your collection, your main character πŸ’–
  • command β€” a bson_t containing the command to execute. yes, the actual command vibe.
  • read_prefs β€” an optional mongoc_read_prefs_t. if you don't pass one, the command uses mode MONGOC_READ_PRIMARY πŸ‘‘
  • reply β€” a maybe-NULL pointer to overwritable storage for a bson_t to contain the results. it's where the tea gets stored πŸ“
  • error β€” an optional location for a bson_error_t or NULL. if you don't want error details, pass NULL and move on πŸ™ˆ

πŸ’… DESCRIPTION πŸ’…

okay so the collection's read preference, read concern, and write concern are not applied to the command. literally not invited to the party. 🚫

the parameter reply is initialized even upon failure to simplify memory management. that's the nice part, bestie β€” cleanup stays less feral. ✨

this function tries to unwrap an embedded error in the command when possible. the unwrapped error will be propagated via the error parameter. additionally, the result document is set in reply. so yeah, it's doing double duty πŸ’…

this function is not considered a retryable read operation. no cap, don't treat it like one. πŸ’€

πŸ’€ ERRORS πŸ’€

errors are propagated via the error parameter. that's the whole mood. 🫢

🌸 RETURNS 🌸

returns true if successful. returns false and sets error if there are invalid arguments or a server or network error. simple as that, fr fr.

⚠️ important vibe check: this function does not check the server response for a write concern error or write concern timeout. periodt.

πŸ¦‹ EXAMPLE πŸ¦‹

the following is an example of executing the ping command. iconic little connectivity moment, iykyk 🌈

          #include <mongoc/mongoc.h>

          #include <bson/bson.h>

          #include <stdio.h>

          static void
          do_ping(mongoc_collection_t *collection)
          {
             bson_error_t error;
             bson_t *cmd;
             bson_t reply;
             char *str;

             cmd = BCON_NEW("ping", BCON_INT32(1));

             if (mongoc_collection_command_simple(collection, cmd, NULL, &reply, &error)) {
                str = bson_as_canonical_extended_json(&reply, NULL);
                printf("Got reply: %s\n", str);
                bson_free(str);
             } else {
                fprintf(stderr, "Got error: %s\n", error.message);
             }

             bson_destroy(&reply);
             bson_destroy(cmd);
          }

πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc

2009-present, MongoDB, Inc.


okay bye bestie πŸ’– this libmongoc page is version 2.5.6, dated Oct 09, 202 as the footer shows it, and it ate. slay πŸŽ€

πŸ“¦ where this page comes from