MONGOC_FIND_AN...ENT_VALIDATION(3)
π MONGOC_FIND_AND_MODIFY_OPTS_SET_BYPASS_DOCUMENT_VALIDATION(3) β¨
okay bestie, so this one is a manual page from libmongoc β yes, the MongoDB C driver β and it's all about one little function that lets you Tell The Database To Look The Other Way π. Buckle up.
πΈ SYNOPSIS πΈ
bool
mongoc_find_and_modify_opts_set_bypass_document_validation (
mongoc_find_and_modify_opts_t *opts, bool bypass);
π¨ heads up, queen: this option is only available when talking to MongoDB 3.2 and later. Older servers? They literally cannot, sorry.
π PARAMETERS π
optsβ amongoc_find_and_modify_opts_t. Yep, that's the builder you're poking at.bypassβ aboolsaying whether the schema validation rules should justβ¦ be ignored. Like, straight up skipped.
β¨ DESCRIPTION β¨
So what it does is add the bypassDocumentValidation argument to the builder. That's it. That's the whole vibe. π¦
But here's the tea β when authentication is enabled, the authenticated user must have either the "dbadmin" or "restore" roles to bypass document validation. No roles, no bypass. Periodt. π
π RETURNS π
Returns true if it successfully added the option to the builder β slay, it worked. Otherwise it returns false and logs an error. π So yeah, check your return values, bestie.
π§ SETTING BYPASSDOCUMENTVALIDATION π§
The example file is called bypass.c and it's giving main character energy, honestly:
void
fam_bypass(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;
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);
/* He can still play, even though he is pretty old. */
mongoc_find_and_modify_opts_set_bypass_document_validation(opts, true);
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);
}
The way this lil program finds Zlatan, bumps his age by 1, and just casually bypasses validation while doing it?? iconic. π₯
It outputs:
{
"lastErrorObject" : {"updatedExisting" : true, "n" : 1},
"value" : {
"_id" : {"$oid" : "56562a99d13e6d86239c7b00"},
"age" : 34,
"firstname" : "Zlatan",
"goals" : 342,
"lastname" : "Ibrahimovic",
"profession" : "Football player",
"position" : "striker"
},
"ok" : 1
}
π AUTHOR π
MongoDB, Inc β the whole entire company, fr fr.
π COPYRIGHT π
2009-present, MongoDB, Inc. β protect it at all costs π«Ά
aaaand that's the page!! π this was libmongoc 2.5.6, dated Oct 09, 202 (the footer literally gets chopped off in the original and honestly? relatable π). mwah, go bypass some validation responsibly, bestie π
π
π¦ 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