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β amongoc_collection_t. your collection, your main character πcommandβ abson_tcontaining the command to execute. yes, the actual command vibe.read_prefsβ an optionalmongoc_read_prefs_t. if you don't pass one, the command uses modeMONGOC_READ_PRIMARYπreplyβ a maybe-NULLpointer to overwritable storage for abson_tto contain the results. it's where the tea gets stored πerrorβ an optional location for abson_error_torNULL. if you don't want error details, passNULLand 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
π COPYRIGHT π
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
- 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