MONGOC_FIND_AN...PTS_SET_UPDATE(3)
okay bestie, you're reading the libmongoc manual page for mongoc_find_and_modify_opts_set_update(3) β header shortens it to MONGOC_FIND_AN...PTS_SET_UPDATE(3), iconic truncation behavior π
β¨
β¨ SYNOPSIS β¨
bool
mongoc_find_and_modify_opts_set_update (mongoc_find_and_modify_opts_t *opts,
const bson_t *update);
π PARAMETERS π
optsβ amongoc_find_and_modify_opts_t. That's the builder bestie in question π«Άupdateβ the update document, and it's in the same format as the update document passed tomongoc_collection_update(). copy that energy exactly, no improv π
π DESCRIPTION π
Adds the update argument to the builder. That's the whole plot. Short, sweet, slay β¨
And the best part: update does not have to remain valid after calling this function. So it can dip out of validity after the call and you don't have to clutch your pearls about it π
π RETURNS π
Returns true if it successfully added the option to the builder, otherwise false. Fr fr, that's the return vibe check β
πΈ SETTING UPDATE πΈ
π update.c
void
fam_update(mongoc_collection_t *collection)
{
mongoc_find_and_modify_opts_t *opts;
bson_t *update;
bson_t reply;
bson_error_t error;
bson_t query = BSON_INITIALIZER;
bool success;
/* Find Zlatan Ibrahimovic */
BSON_APPEND_UTF8(&query, "firstname", "Zlatan");
BSON_APPEND_UTF8(&query, "lastname", "Ibrahimovic");
/* Make him a book author */
update = BCON_NEW("$set", "{", "author", BCON_BOOL(true), "}");
opts = mongoc_find_and_modify_opts_new();
/* Note that the document returned is the _previous_ version of the document
* To fetch the modified new version, use
* mongoc_find_and_modify_opts_set_flags (opts,
* MONGOC_FIND_AND_MODIFY_RETURN_NEW);
*/
mongoc_find_and_modify_opts_set_update(opts, update);
success = mongoc_collection_find_and_modify_with_opts(collection, &query, opts, &reply, &error);
if (success) {
char *str;
str = bson_as_canonical_extended_json(&reply, NULL);
printf("%s\n", str);
bson_free(str);
} else {
fprintf(stderr, "Got error: \"%s\" on line %d\n", error.message, (int)(__LINE__));
}
bson_destroy(&reply);
bson_destroy(update);
bson_destroy(&query);
mongoc_find_and_modify_opts_destroy(opts);
}
Outputs:
{
"lastErrorObject" : {"updatedExisting" : true, "n" : 1},
"value" : {
"_id" : {"$oid" : "56562a99d13e6d86239c7b00"},
"age" : 35,
"firstname" : "Zlatan",
"goals" : 342,
"lastname" : "Ibrahimovic",
"profession" : "Football player",
"position" : "striker"
},
"ok" : 1
}
π AUTHOR π
MongoDB, Inc
π COPYRIGHT π
2009-present, MongoDB, Inc.
that's the page, bestie π«Ά footer sign-off: version 2.5.6, dated Oct 09, 202 β yes, the date is literally printed like that in the source, don't come for me πβ¨ stay slay and may your builders return true π
π¦ 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