[CDRIVER-2959] "validate" option is passed in command Created: 11/Feb/19  Updated: 28/Oct/23  Resolved: 12/Feb/19

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: 1.10.3
Fix Version/s: 1.14.0

Type: Bug Priority: Blocker - P1
Reporter: Kevin Albertson Assignee: Kevin Albertson
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CDRIVER-2373 IDL for functions that take flexible ... Closed
is related to CDRIVER-2265 Overly validating documents in bulk i... Closed

 Description   

I noticed the "validate" option had broken our performance tests on newer MongoDB.

The "validate" option dictates whether or not we validate user supplied BSON documents before adding them to the relevant operation:

However, this option appears to be broken. We must not send this as part of the command but it appears we do. A test like this fails:

static void
test_validate_option (void)
{
   mongoc_client_t *client = test_framework_client_new ();
   mongoc_collection_t *coll =
      mongoc_client_get_collection (client, "db", "coll");
   bson_error_t error;
   bson_t reply;
   bool ret;
 
   /* Test setting "validate" for any set of options that take it. */
   mongoc_bulk_operation_t *bulk;
   bulk = mongoc_collection_create_bulk_operation (coll, false, NULL);
   ret = mongoc_bulk_operation_insert_with_opts (
      bulk,
      BCON_NEW ("x", BCON_INT32 (1)),
      BCON_NEW ("validate", BCON_INT32 (BSON_VALIDATE_DOLLAR_KEYS)),
      &error);
 
   ASSERT_OR_PRINT (ret, error);
 
   ret = mongoc_bulk_operation_execute (bulk, &reply, &error)
   ASSERT_OR_PRINT (ret, error);
 
   bson_destroy (&reply);
   mongoc_collection_destroy (coll);
   mongoc_client_destroy (client);
}

With an error message:

Unknown option to insert command: validate

I've confirmed with wireshark that we are sending "valildate" as part of the insert command, and that the server is generating this error.

This seems to go back as far as 1.10 (possibly this was introduced in IDL parsing of CDRIVER-2373). Our existing validate tests don't seem to check the successful case, where we expect validation to succeed.

It seems MongoDB 3.2 didn't care that we sent the extra "validate" option and just ignored it. But newer (at least 3.6, haven't checked 3.4) does.



 Comments   
Comment by Githook User [ 11/Feb/19 ]

Author:

{'name': 'Kevin Albertson', 'email': 'kevin.albertson@mongodb.com', 'username': 'kevinAlbs'}

Message: CDRIVER-2959 fix 'validate' for bulk insert
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/5f5e804a76c85668ab6ecc3451e5fbf22b0642f1

Comment by Kevin Albertson [ 11/Feb/19 ]

Only appears to affect bulk insert. "validate" was added as a bulk option in CDRIVER-2265.

Generated at Wed Feb 07 21:16:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.