[DRIVERS-955] How should drivers report write concern error returned as part of a command error Created: 16/Dec/19  Updated: 31/Mar/22

Status: Backlog
Project: Drivers
Component/s: CRUD, Read and Write Concern
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Patrick Freed Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related

 Description   

Typically, write concern errors are only be returned as part of the response to write commands, and in those cases the response will always be ok: 1.

There are some other cases in which a write concern error can be returned outside of such a context, such as aggregate with $merge (see SERVER-44827). In those cases, a write concern error can be included in both ok: 0 (i.e. command error) and ok: 1 responses. It is unclear how statically typed drivers (which have separate structures for WriteException and CommandException) are expected to handle this.

A few options are possible:

  • When encountering ok: 1 + WC error, throw a WriteException. When encountering ok: 0 + WC error, discard the WC error and throw a CommandException.
  • Amend CommandException to have an option WC error field. Still throw WriteError in the ok: 1 case.

I'm not sure if either of these options are desirable though. Another more drastic solution would be to separate $out and $merge into their own helpers and advise users against using the stages directly in their own pipelines, similar to how we handle the $changeStream stage. This would allow us to define more specific errors for these cases, but it may be too late in the game to start doing that (for $out at least).


Generated at Thu Feb 08 08:22:40 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.