[CDRIVER-473] mongoc_collection_update() should provide access to WriteResult Created: 29/Nov/14  Updated: 03/May/17  Resolved: 15/Jul/15

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

Type: Improvement Priority: Minor - P4
Reporter: Tim Dorcey Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Minor Change

 Description   

There does not appear to be a way to determine whether a mongoc_collection_update failed to locate any documents that satisfy the query. I would expect this is an error condition in many applications (in my case it revealed a thread race issue).

I have found 2 work arounds. One is to put the update into a bulk operation and look at the reply from mongoc_bulk_operation_execute(). The other is to use mongoc_collection_find_and_modify() and request at least one field return. Any comment on which is more efficient?



 Comments   
Comment by A. Jesse Jiryu Davis [ 15/Jul/15 ]

mongoc_collection_update now sets the collection's GLE to a WriteResult with full information, like:

{ "nInserted" : 0, "nMatched" : 1, "nRemoved" : 0, "nUpserted" : 0, "writeErrors" : [  ] }

See here for more info about WriteResult contents, it applies equally to bulk operations and to mongoc_collection_update:

http://api.mongodb.org/c/current/bulk.html

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