[CDRIVER-945] mongoc_collection_find_and_modify_with_opts () builder Created: 19/Oct/15  Updated: 27/May/16  Resolved: 18/Nov/15

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: None
Fix Version/s: 1.3.0-beta0

Type: Improvement Priority: Major - P3
Reporter: Matt Cotter Assignee: Hannes Magnusson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CDRIVER-893 Support bypassDocumentValidation Closed
related to CDRIVER-1048 Add generic mongoc_find_and_modify_op... Closed
related to CXX-693 findAndModify take a write concern Closed
related to CDRIVER-824 collection_find_and_modify() should a... Closed
related to CDRIVER-1008 Document new find_and_modify builder Closed
is related to CDRIVER-1047 Add mongoc_find_and_modify_opts_set_m... Closed
is related to CXX-690 Support bypassDocumentValidation Closed
Epic Link: MongoDB 3.2

 Description   

We need a way to be able to extend the mongoc_collection_find_and_modify () helper for new options, for example bypassDocumentValidation.

                                                                             
typedef enum                                                                         
{                                                                                    
   MONGOC_FIND_AND_MODIFY_NONE   = 0,                                                
   MONGOC_FIND_AND_MODIFY_REMOVE = 1 << 0,                                           
   MONGOC_FIND_AND_MODIFY_UPSERT = 1 << 1,                                           
   MONGOC_FIND_AND_MODIFY_RETURN_NEW = 1 << 2,                                       
} mongoc_find_and_modify_flags_t;                                                    
                                                                                     
typedef struct _mongoc_find_and_modify_opts_t mongoc_find_and_modify_opts_t ;        

                                                                             
mongoc_find_and_modify_opts_t* mongoc_find_and_modify_opts_new  (void);
bool mongoc_find_and_modify_opts_set_sort                       (mongoc_find_and_modify_opts_t *opts, const bson_t                         *sort);
bool mongoc_find_and_modify_opts_set_update                     (mongoc_find_and_modify_opts_t *opts, const bson_t                         *update);
bool mongoc_find_and_modify_opts_set_fields                     (mongoc_find_and_modify_opts_t *opts, const bson_t                         *fields);
bool mongoc_find_and_modify_opts_set_flags                      (mongoc_find_and_modify_opts_t *opts, const mongoc_find_and_modify_flags_t  flags);
bool mongoc_find_and_modify_opts_set_bypass_document_validation (mongoc_find_and_modify_opts_t *opts,       bool                            bypass);
void mongoc_find_and_modify_opts_destroy                        (mongoc_find_and_modify_opts_t *opts);

                                                                             
bool mongoc_collection_find_and_modify_with_opts (mongoc_collection_t                 *collection,
                                                  const bson_t                        *query,
                                                  const mongoc_find_and_modify_opts_t *opts,
                                                  bson_t                              *reply,
                                                  bson_error_t                        *error);

Note that setting write_concern is not supported through the builder.
Write concern must be set the collection level, which findAndModify will "inherit" and use when talking to MongoDB 3.2 and later.

mongoc_collection_set_write_concern (collection, write_concern);
mongoc_collection_find_and_modify_with_opts (collection, query, find_and_modify_opts, &reply, &error);



 Comments   
Comment by Githook User [ 18/Nov/15 ]

Author:

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

Message: CDRIVER-945: Change of hearts. Remove _set_write_concern

For consistency with all other helpers, the write concern should be set
at the collection level, not per command.
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/a8fe81004ea1f0379961317ba341a8a7b5d96ca2

Comment by Hannes Magnusson [ 16/Nov/15 ]

https://github.com/mongodb/specifications/blob/master/source/read-write-concern/read-write-concern.rst#location-specification-1

WriteConcern SHOULD be specifiable at the Client, Database, and Collection levels. Unless specified, the value MUST be inherited from its parent and SHOULD NOT be modifiable on an existing Client, Database, and Collection. In addition, a driver MAY allow it to be specified on a per-operation basis in accordance with the CRUD specification.

Note the "MAY".

There is no need for mongoc to create a full new infrastructure to be able to handle per-operation WriteConcern.
Since we do need this though for the bypassDocumentValidation flag, we'll keep the find_and_modify_with_opts() builder – but the mongoc_find_and_modify_opts_set_write_concern() function is being removed.

Comment by Githook User [ 11/Nov/15 ]

Author:

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

Message: CDRIVER-945: Add tests for find_and_modify_with_opts
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/44bba4b140ace65203a61ae212e912605644e5b2

Comment by Githook User [ 11/Nov/15 ]

Author:

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

Message: CDRIVER-945: Generate new find_and_modify_with_opts futures
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/85f354424a089982c8f14b22482989d7fc12cb9c

Comment by Githook User [ 11/Nov/15 ]

Author:

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

Message: CDRIVER-945: Export the new find_and_modify helpers
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/89fec89e8fc5824b5d8441ad3b3ee7bba67bd644

Comment by Githook User [ 11/Nov/15 ]

Author:

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

Message: CDRIVER-945: Use mongoc_collection_find_and_modify_with_opts
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/676a71af81abd8492e327bde54aa973cb30b617a

Comment by Githook User [ 11/Nov/15 ]

Author:

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

Message: CDRIVER-945: Add mongoc_collection_find_and_modify_with_opts ()
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/1204dc20bb31d4dc126fea3efbfb3a23283292fa

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