MONGOC_FIND_A...ET_MAX_TIME_MS(3)
π
mongoc_find_and_modify_opts_set_max_time_ms π
okay so bestie, this is the libmongoc manual page for setting a maxTimeMS on your findAndModify options. itβs giving βplease donβt let this server-side operation run foreverβ energy, and honestly? iconic. β¨
β¨ SYNOPSIS β¨
bool
mongoc_find_and_modify_opts_set_max_time_ms (
mongoc_find_and_modify_opts_t *opts, uint32_t max_time_ms);
π PARAMETERS π
optsβ amongoc_find_and_modify_opts_t. thatβs your builder bestie πmax_time_msβ the maximum server-side execution time permitted, in milliseconds, or0to specify no maximum time (the default setting). so0is lowkey βno cap, take forever if you wantβ π
π DESCRIPTION π
Adds a maxTimeMS argument to the builder. literally thatβs the whole vibe. π¦
πΈ RETURNS πΈ
Returns true if it successfully added the option to the builder, otherwise false and logs an error. no silent failures here, bestie π
Note: althoughmax_time_msis auint32_t, it is possible to set it as auint64_tthrough the options arguments in some cursor returning functions likemongoc_collection_find_with_opts().
π SETTING MAXTIMEMS π
opts.c:
void
fam_opts(mongoc_collection_t *collection)
{
mongoc_find_and_modify_opts_t *opts;
bson_t reply;
bson_t *update;
bson_error_t error;
bson_t query = BSON_INITIALIZER;
mongoc_write_concern_t *wc;
bson_t extra = BSON_INITIALIZER;
bool success;
/* Find Zlatan Ibrahimovic, the striker */
BSON_APPEND_UTF8(&query, "firstname", "Zlatan");
BSON_APPEND_UTF8(&query, "lastname", "Ibrahimovic");
BSON_APPEND_UTF8(&query, "profession", "Football player");
/* Bump his age */
update = BCON_NEW("$inc", "{", "age", BCON_INT32(1), "}");
opts = mongoc_find_and_modify_opts_new();
mongoc_find_and_modify_opts_set_update(opts, update);
/* Abort if the operation takes too long. */
mongoc_find_and_modify_opts_set_max_time_ms(opts, 100);
/* Set write concern w: 2 */
wc = mongoc_write_concern_new();
mongoc_write_concern_set_w(wc, 2);
mongoc_write_concern_append(wc, &extra);
/* Some future findAndModify option the driver doesn't support conveniently
*/
BSON_APPEND_INT32(&extra, "futureOption", 42);
mongoc_find_and_modify_opts_append(opts, &extra);
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(&extra);
bson_destroy(update);
bson_destroy(&query);
mongoc_write_concern_destroy(wc);
mongoc_find_and_modify_opts_destroy(opts);
}
π AUTHOR π
MongoDB, Inc
π COPYRIGHT π
2009-present, MongoDB, Inc.
mwah π this page is from libmongoc version 2.5.6, dated Oct 09, 2026. bye bestie, go set those timeouts π«Άβ¨
π¦ 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