GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
MONGOC_FIND_AND_MODIFY_OPTS_SET_BYPASS_DOCUMENT_VALIDATION(3) libmongoc MONGOC_FIND_AND_MODIFY_OPTS_SET_BYPASS_DOCUMENT_VALIDATION(3)

bool
mongoc_find_and_modify_opts_set_bypass_document_validation (

mongoc_find_and_modify_opts_t *opts, bool bypass);


This option is only available when talking to MongoDB 3.2 and later.

  • opts: A mongoc_find_and_modify_opts_t.
  • bypass: If the schema validation rules should be ignored.

Adds bypassDocumentValidation argument to the builder.

When authentication is enabled, the authenticated user must have either the "dbadmin" or "restore" roles to bypass document validation.

Returns true if it successfully added the option to the builder, otherwise false and logs an error.

bypass.c

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); }


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 }


MongoDB, Inc

2009-present, MongoDB, Inc.

July 3, 2025 1.30.4

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.