@@ -41,14 +41,25 @@ func Direct(direct bool) MongoOption {
41
41
// If the option is not specified the default is: [readconcern.Majority].
42
42
func ReadConcern (readConcern * readconcern.ReadConcern ) MongoOption {
43
43
return func (opts * options.ClientOptions ) error {
44
- if readConcern = = nil {
45
- return errors . New ( "ReadConcern not specified" )
44
+ if err := validateReadConcern ( readConcern ); err ! = nil {
45
+ return err
46
46
}
47
47
opts .SetReadConcern (readConcern )
48
48
return nil
49
49
}
50
50
}
51
51
52
+ func validateReadConcern (readConcern * readconcern.ReadConcern ) error {
53
+ if readConcern == nil {
54
+ return errors .New ("ReadConcern not specified" )
55
+ }
56
+ if readConcern .Level != readconcern .Local ().Level &&
57
+ readConcern .Level != readconcern .Majority ().Level {
58
+ return errors .New ("ReadConcern level is not allowed" )
59
+ }
60
+ return nil
61
+ }
62
+
52
63
// WriteConcern option sets level of acknowledgment for write operation.
53
64
// For PBM typically use: [writeconcern.W1] or [writeconcern.Majority].
54
65
// If the option is not specified the default is: [writeconcern.Majority].
@@ -147,6 +158,13 @@ func validateConnStringOpts(opts *options.ClientOptions) error {
147
158
if err = validateWriteConcern (opts .WriteConcern ); err != nil {
148
159
return err
149
160
}
161
+ if err = validateReadConcern (opts .ReadConcern ); err != nil {
162
+ return err
163
+ }
164
+ if opts .ReadConcern .Level == readconcern .Majority ().Level &&
165
+ opts .WriteConcern .W == writeconcern .W1 ().W {
166
+ return errors .New ("ReadConcern majority and WriteConcern 1 is not allowed" )
167
+ }
150
168
151
169
return nil
152
170
}
0 commit comments