@@ -27,18 +27,25 @@ public struct WriteConcern: Codable {
2727 public static let serverDefault = WriteConcern ( )
2828
2929 /// An option to request acknowledgement that the write operation has propagated to specified mongod instances.
30+ /// - SeeAlso: https://docs.mongodb.com/manual/reference/write-concern/#w-option
3031 public enum W : Codable , Equatable {
31- /// Specifies the number of nodes that should acknowledge the write. MUST be greater than or equal to 0.
32+ /// Requests acknowledgment that the write operation has propagated to the specified number of mongod
33+ /// instances. MUST be greater than or equal to 0.
3234 case number( Int )
33- /// Indicates a tag for nodes that should acknowledge the write.
34- case tag( String )
35- /// Specifies that a majority of nodes should acknowledge the write.
35+ /// Requests acknowledgment that write operations have propagated to the majority of the data-bearing voting
36+ /// members.
3637 case majority
38+ // swiftlint:disable line_length
39+ /// Requests acknowledgement that the write operation has propagated to tagged members that satisfy the custom
40+ /// write concern with the specified name.
41+ /// - SeeAlso: https://docs.mongodb.com/manual/reference/write-concern/#writeconcern.%3Ccustom-write-concern-name%3E
42+ case custom( String )
43+ // swiftlint:enable line_length
3744
3845 public init ( from decoder: Decoder ) throws {
3946 let container = try decoder. singleValueContainer ( )
4047 if let string = try ? container. decode ( String . self) {
41- self = string == " majority " ? . majority : . tag ( string)
48+ self = string == " majority " ? . majority : . custom ( string)
4249 } else {
4350 let wNumber = try container. decode ( Int . self)
4451 self = . number( wNumber)
@@ -57,8 +64,8 @@ public struct WriteConcern: Codable {
5764 message: " Invalid WriteConcern.w \( wNumber) : must be between 0 and \( Int32 . max) "
5865 )
5966 }
60- case let . tag ( wTag ) :
61- try container. encode ( wTag )
67+ case let . custom ( name ) :
68+ try container. encode ( name )
6269 case . majority:
6370 try container. encode ( " majority " )
6471 }
@@ -152,8 +159,8 @@ public struct WriteConcern: Codable {
152159 case MONGOC_WRITE_CONCERN_W_MAJORITY:
153160 self . w = . majority
154161 case MONGOC_WRITE_CONCERN_W_TAG:
155- if let wTag = mongoc_write_concern_get_wtag ( writeConcern) {
156- self . w = . tag ( String ( cString: wTag ) )
162+ if let name = mongoc_write_concern_get_wtag ( writeConcern) {
163+ self . w = . custom ( String ( cString: name ) )
157164 } else {
158165 self . w = nil
159166 }
@@ -187,8 +194,8 @@ public struct WriteConcern: Codable {
187194 switch w {
188195 case let . number( wNumber) :
189196 mongoc_write_concern_set_w ( writeConcern, Int32 ( wNumber) )
190- case let . tag ( wTag ) :
191- mongoc_write_concern_set_wtag ( writeConcern, wTag )
197+ case let . custom ( name ) :
198+ mongoc_write_concern_set_wtag ( writeConcern, name )
192199 case . majority:
193200 mongoc_write_concern_set_w ( writeConcern, MONGOC_WRITE_CONCERN_W_MAJORITY)
194201 }
0 commit comments