@@ -191,7 +191,7 @@ func (coll *Collection) BulkWrite(ctx context.Context, models []WriteModel,
191
191
}
192
192
}
193
193
194
- return & BulkWriteResult {}, err
194
+ return & BulkWriteResult {}, replaceTopologyErr ( err )
195
195
}
196
196
197
197
return & BulkWriteResult {
@@ -339,7 +339,7 @@ func (coll *Collection) InsertMany(ctx context.Context, documents []interface{},
339
339
case command .ErrUnacknowledgedWrite :
340
340
return & InsertManyResult {InsertedIDs : result }, ErrUnacknowledgedWrite
341
341
default :
342
- return nil , err
342
+ return nil , replaceTopologyErr ( err )
343
343
}
344
344
if len (res .WriteErrors ) > 0 || res .WriteConcernError != nil {
345
345
bwErrors := make ([]BulkWriteError , 0 , len (res .WriteErrors ))
@@ -523,7 +523,7 @@ func (coll *Collection) updateOrReplaceOne(ctx context.Context, filter,
523
523
opts ... ,
524
524
)
525
525
if err != nil && err != command .ErrUnacknowledgedWrite {
526
- return nil , err
526
+ return nil , replaceTopologyErr ( err )
527
527
}
528
528
529
529
res := & UpdateResult {
@@ -645,7 +645,7 @@ func (coll *Collection) UpdateMany(ctx context.Context, filter interface{}, upda
645
645
opts ... ,
646
646
)
647
647
if err != nil && err != command .ErrUnacknowledgedWrite {
648
- return nil , err
648
+ return nil , replaceTopologyErr ( err )
649
649
}
650
650
res := & UpdateResult {
651
651
MatchedCount : r .MatchedCount ,
@@ -760,7 +760,7 @@ func (coll *Collection) Aggregate(ctx context.Context, pipeline interface{},
760
760
Clock : coll .client .clock ,
761
761
}
762
762
763
- return dispatch .Aggregate (
763
+ cursor , err := dispatch .Aggregate (
764
764
ctx , cmd ,
765
765
coll .client .topology ,
766
766
coll .readSelector ,
@@ -770,6 +770,8 @@ func (coll *Collection) Aggregate(ctx context.Context, pipeline interface{},
770
770
coll .registry ,
771
771
aggOpts ,
772
772
)
773
+
774
+ return cursor , replaceTopologyErr (err )
773
775
}
774
776
775
777
// Count gets the number of documents matching the filter. A user can supply a
@@ -812,7 +814,7 @@ func (coll *Collection) Count(ctx context.Context, filter interface{},
812
814
Clock : coll .client .clock ,
813
815
}
814
816
815
- return dispatch .Count (
817
+ count , err := dispatch .Count (
816
818
ctx , cmd ,
817
819
coll .client .topology ,
818
820
coll .readSelector ,
@@ -821,6 +823,8 @@ func (coll *Collection) Count(ctx context.Context, filter interface{},
821
823
coll .registry ,
822
824
opts ... ,
823
825
)
826
+
827
+ return count , replaceTopologyErr (err )
824
828
}
825
829
826
830
// CountDocuments gets the number of documents matching the filter. A user can supply a
@@ -864,7 +868,7 @@ func (coll *Collection) CountDocuments(ctx context.Context, filter interface{},
864
868
Clock : coll .client .clock ,
865
869
}
866
870
867
- return dispatch .CountDocuments (
871
+ count , err := dispatch .CountDocuments (
868
872
ctx , cmd ,
869
873
coll .client .topology ,
870
874
coll .readSelector ,
@@ -873,6 +877,8 @@ func (coll *Collection) CountDocuments(ctx context.Context, filter interface{},
873
877
coll .registry ,
874
878
countOpts ,
875
879
)
880
+
881
+ return count , replaceTopologyErr (err )
876
882
}
877
883
878
884
// EstimatedDocumentCount gets an estimate of the count of documents in a collection using collection metadata.
@@ -910,7 +916,7 @@ func (coll *Collection) EstimatedDocumentCount(ctx context.Context,
910
916
countOpts = countOpts .SetMaxTime (* opts [len (opts )- 1 ].MaxTime )
911
917
}
912
918
913
- return dispatch .Count (
919
+ count , err := dispatch .Count (
914
920
ctx , cmd ,
915
921
coll .client .topology ,
916
922
coll .readSelector ,
@@ -919,6 +925,8 @@ func (coll *Collection) EstimatedDocumentCount(ctx context.Context,
919
925
coll .registry ,
920
926
countOpts ,
921
927
)
928
+
929
+ return count , replaceTopologyErr (err )
922
930
}
923
931
924
932
// Distinct finds the distinct values for a specified field across a single
@@ -976,7 +984,7 @@ func (coll *Collection) Distinct(ctx context.Context, fieldName string, filter i
976
984
opts ... ,
977
985
)
978
986
if err != nil {
979
- return nil , err
987
+ return nil , replaceTopologyErr ( err )
980
988
}
981
989
982
990
return res .Values , nil
@@ -1026,7 +1034,7 @@ func (coll *Collection) Find(ctx context.Context, filter interface{},
1026
1034
Clock : coll .client .clock ,
1027
1035
}
1028
1036
1029
- return dispatch .Find (
1037
+ cursor , err := dispatch .Find (
1030
1038
ctx , cmd ,
1031
1039
coll .client .topology ,
1032
1040
coll .readSelector ,
@@ -1035,6 +1043,8 @@ func (coll *Collection) Find(ctx context.Context, filter interface{},
1035
1043
coll .registry ,
1036
1044
opts ... ,
1037
1045
)
1046
+
1047
+ return cursor , replaceTopologyErr (err )
1038
1048
}
1039
1049
1040
1050
// FindOne returns up to one document that matches the model. A user can
@@ -1115,7 +1125,7 @@ func (coll *Collection) FindOne(ctx context.Context, filter interface{},
1115
1125
findOpts ... ,
1116
1126
)
1117
1127
if err != nil {
1118
- return & DocumentResult {err : err }
1128
+ return & DocumentResult {err : replaceTopologyErr ( err ) }
1119
1129
}
1120
1130
1121
1131
return & DocumentResult {cur : cursor , reg : coll .registry }
@@ -1178,7 +1188,7 @@ func (coll *Collection) FindOneAndDelete(ctx context.Context, filter interface{}
1178
1188
opts ... ,
1179
1189
)
1180
1190
if err != nil {
1181
- return & DocumentResult {err : err }
1191
+ return & DocumentResult {err : replaceTopologyErr ( err ) }
1182
1192
}
1183
1193
1184
1194
return & DocumentResult {rdr : res .Value , reg : coll .registry }
@@ -1247,7 +1257,7 @@ func (coll *Collection) FindOneAndReplace(ctx context.Context, filter interface{
1247
1257
opts ... ,
1248
1258
)
1249
1259
if err != nil {
1250
- return & DocumentResult {err : err }
1260
+ return & DocumentResult {err : replaceTopologyErr ( err ) }
1251
1261
}
1252
1262
1253
1263
return & DocumentResult {rdr : res .Value , reg : coll .registry }
@@ -1316,7 +1326,7 @@ func (coll *Collection) FindOneAndUpdate(ctx context.Context, filter interface{}
1316
1326
opts ... ,
1317
1327
)
1318
1328
if err != nil {
1319
- return & DocumentResult {err : err }
1329
+ return & DocumentResult {err : replaceTopologyErr ( err ) }
1320
1330
}
1321
1331
1322
1332
return & DocumentResult {rdr : res .Value , reg : coll .registry }
@@ -1368,7 +1378,7 @@ func (coll *Collection) Drop(ctx context.Context) error {
1368
1378
coll .client .topology .SessionPool ,
1369
1379
)
1370
1380
if err != nil && ! command .IsNotFound (err ) {
1371
- return err
1381
+ return replaceTopologyErr ( err )
1372
1382
}
1373
1383
return nil
1374
1384
}
0 commit comments