[CDRIVER-2296] Option to pass bson_validate_flags_t to update/insert functions Created: 22/Sep/17 Updated: 28/Oct/23 Resolved: 12/Dec/17 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | libmongoc |
| Affects Version/s: | None |
| Fix Version/s: | 1.10.0 |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Lars Lundstedt [X] | Assignee: | Xiangyu Yao (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||
| Description |
|
There is currently no way of controlling what the insert/update functions check for when validating BSON documents prior to insert/update. For example, a client can not ask the validation function called by mongoc_collection_update() to validate the BSON and tell it to allow empty keys. This can of course be worked around by explicitly calling bson_validate() with the desired flags and then calling insert/update with MONGOC_INSERT/UPDATE_NO_VALIDATE set, but that adds a little bit of complexity and some code clutter to client code. It would be handy to just be able to pass bson_validate_flags_t to the insert/update calls. |
| Comments |
| Comment by Githook User [ 02/Feb/18 ] |
|
Author: {'email': 'jesse@mongodb.com', 'name': 'A. Jesse Jiryu Davis', 'username': 'ajdavis'}Message: |
| Comment by Githook User [ 12/Dec/17 ] |
|
Author: {'name': 'Xiangyu Yao', 'email': 'xiangyu.yao24@gmail.com', 'username': 'xy24'}Message: |
| Comment by Xiangyu Yao (Inactive) [ 08/Dec/17 ] |
|
jesse I think
should be
Base on how we use it eventually: link |
| Comment by Githook User [ 14/Nov/17 ] |
|
Author: {'name': 'A. Jesse Jiryu Davis', 'username': 'ajdavis', 'email': 'jesse@mongodb.com'}Message: |
| Comment by A. Jesse Jiryu Davis [ 29/Oct/17 ] |
|
I'm beginning this API for the new CRUD functions in 1.9.0. The functions are:
These will now accept an option with field name "validate". If its value is falsey according to bson_iter_as_bool (false, 0, null, ...) then no validation is performed. If it's exactly "true" then the driver does standard validation. Finer control (check UTF-8, allow NIL or "$" or "." or empty keys) will be designed and implemented later. |
| Comment by A. Jesse Jiryu Davis [ 24/Oct/17 ] |
|
We could define a way to pass validation options in a bson_t to all the new _with_opts functions, e.g. if you pass 'allowEmptyKeys': true to mongoc_collection_insert_with_opts it'll allow empty keys. Update the validate functions in mongoc-util.c: _mongoc_validate_new_document, _mongoc_validate_replace, and _mongoc_validate_update. We need a function that converts from a bson_t *opts to a bson_validate_flags_t bit field, and uses that to override the default validate flags used by those three functions. Let's interpret fields in "opts" like so:
Otherwise:
|