[CDRIVER-1779] mongoc_collection_find_and_modify_with_opts() should return error if collation specified and connection max wire version < 5 Created: 18/Oct/16  Updated: 15/Nov/16  Resolved: 19/Oct/16

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.5.0

Type: Bug Priority: Major - P3
Reporter: J Rassi Assignee: Hannes Magnusson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CXX-971 Support providing collation per opera... Closed
is depended on by CXX-1132 Test that collection::find(), collect... Closed
Related
related to CDRIVER-1751 mongoc_collection_find_with_opts() sh... Closed

 Description   

mongoc_collection_find_and_modify_with_opts() should return an error to the user if a collation is specified and the connection max wire version is less than 5. Currently, no error is returned to the user, and the collation is passed through to the server and ignored. Tested with libmongoc 1.5.0-rc2 against server version 3.2.10.

Relevant excerpt from the collation spec:

Drivers therefore MUST throw an error if a user specifies a Collation and the selected server has a maxWireVersion < 5 or if using opcode-based unacknowledged writes.



 Comments   
Comment by Githook User [ 19/Oct/16 ]

Author:

{u'username': u'bjori', u'name': u'Hannes Magnusson', u'email': u'bjori@php.net'}

Message: CDRIVER-1779 fam+collation should error if max_wire_version<5
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/d1c74abeee1be66f7608507eec12926e9205589b

Comment by J Rassi [ 18/Oct/16 ]

My original repro for this was with code in the C++ driver that hasn't shipped yet, though I've modified the existing find_and_modify_with_opts example file below to demonstrate the issue:

#include <bcon.h>
#include <mongoc.h>
 
void fam_collation(mongoc_collection_t *collection)
{
   mongoc_find_and_modify_opts_t *opts;
   bson_t *update;
   bson_t *collation;
   bson_t reply;
   bson_error_t error;
   bson_t query = BSON_INITIALIZER;
   bool success;
 
   /* Find all users with the lastname Ibrahimovic */
   BSON_APPEND_UTF8 (&query, "lastname", "Ibrahimovic");
 
   /* Bump his goal tally */
   update = BCON_NEW ("$set", "{",
      "oldest", BCON_BOOL (true),
   "}");
 
   collation = BCON_NEW ("collation", "{", "locale", "en_US", "strength", BCON_INT32 (2), "}");
 
   opts = mongoc_find_and_modify_opts_new ();
   mongoc_find_and_modify_opts_set_update (opts, update);
 
   mongoc_find_and_modify_opts_append (opts, collation);
 
   success = mongoc_collection_find_and_modify_with_opts (collection, &query, opts, &reply, &error);
 
   if (success) {
      char *str;
 
      str = bson_as_json (&reply, NULL);
      printf ("%s\n", str);
      bson_free (str);
   } else {
      fprintf(stderr, "Got error: \"%s\" on line %d\n", error.message, __LINE__);
   }
 
   bson_destroy (&reply);
   bson_destroy (update);
   bson_destroy (collation);
   bson_destroy (&query);
   mongoc_find_and_modify_opts_destroy (opts);
}
 
int main(void)
{
   mongoc_collection_t *collection;
   mongoc_database_t *database;
   mongoc_client_t *client;
   bson_error_t error;
 
   mongoc_init();
   client = mongoc_client_new ("mongodb://localhost:27017/admin?appname=find-and-modify-opts-example");
   mongoc_client_set_error_api (client, 2);
   database = mongoc_client_get_database (client, "databaseName");
 
   collection = mongoc_database_create_collection (database, "collectionName", NULL, &error);
   if (!collection) {
      fprintf(stderr, "Got error: \"%s\" on line %d\n", error.message, __LINE__);
      return 1;
   }
 
   fam_collation (collection);
 
   mongoc_collection_drop (collection, NULL);
   mongoc_database_destroy (database);
   mongoc_collection_destroy (collection);
   mongoc_client_destroy (client);
 
   mongoc_cleanup ();
   return 0;
}

With libmongoc 1.5.0-rc2 and server version 3.2.10, mongoc_collection_find_and_modify_with_opts() in the above example returns true, but I would expect it to return false.

Comment by Hannes Magnusson [ 18/Oct/16 ]

Would you happen to still have the repro around?

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