Skip to content

Commit c1a8c80

Browse files
authored
REP-6771 Update to Go driver v2 (#152)
The updates here are mostly mechanical. For example, `primitive.Timestamp` becomes `bson.Timestamp`, and `mongo.SessionContext` is now just `context.Context`. One nontriviality is that, because the v2 driver removed some useful introspection APIs, the guard rails to check read & write concern are temporarily removed. They will be restored in REP-6772, once the driver re-adds those to driver v2.
1 parent 564bc64 commit c1a8c80

File tree

458 files changed

+84181
-4359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

458 files changed

+84181
-4359
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ linters:
2828
failOn: all
2929
govet:
3030
disable:
31-
# Unkeyed primitive.E and timestamp fields are used extensively in code taken from
31+
# Unkeyed bson.E and timestamp fields are used extensively in code taken from
3232
# mongosync.
3333
- composites
3434
exclusions:

dockey/agg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package dockey
66
import (
77
"github.com/10gen/migration-verifier/mslices"
88
"github.com/samber/lo"
9-
"go.mongodb.org/mongo-driver/bson"
9+
"go.mongodb.org/mongo-driver/v2/bson"
1010
)
1111

1212
// ExtractTrueDocKeyAgg returns an aggregation expression that extracts the

dockey/raw.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66

77
"github.com/10gen/migration-verifier/mslices"
88
"github.com/pkg/errors"
9-
"go.mongodb.org/mongo-driver/bson"
10-
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
9+
"go.mongodb.org/mongo-driver/v2/bson"
10+
"go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore"
1111
)
1212

1313
// ExtractTrueDocKeyFromDoc extracts the document key from a document
@@ -43,7 +43,7 @@ func ExtractTrueDocKeyFromDoc(
4343
docBuilder.AppendValue(
4444
field,
4545
bsoncore.Value{
46-
Type: val.Type,
46+
Type: bsoncore.Type(val.Type),
4747
Data: val.Value,
4848
},
4949
)

dockey/raw_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/10gen/migration-verifier/dockey/test"
88
"github.com/stretchr/testify/assert"
99
"github.com/stretchr/testify/require"
10-
"go.mongodb.org/mongo-driver/bson"
10+
"go.mongodb.org/mongo-driver/v2/bson"
1111
)
1212

1313
func TestExtractTrueDocKeyFromDoc(t *testing.T) {

dockey/test/cases.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package test
22

33
import (
44
"github.com/10gen/migration-verifier/mslices"
5-
"go.mongodb.org/mongo-driver/bson"
5+
"go.mongodb.org/mongo-driver/v2/bson"
66
)
77

88
type TestCase struct {

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ require (
1414
github.com/pkg/errors v0.9.1
1515
github.com/quasilyte/go-ruleguard/dsl v0.3.22
1616
github.com/rs/zerolog v1.34.0
17-
github.com/samber/lo v1.47.0
17+
github.com/samber/lo v1.52.0
1818
github.com/samber/mo v1.13.0
1919
github.com/stretchr/testify v1.10.0
2020
github.com/urfave/cli v1.22.9
2121
go.mongodb.org/mongo-driver v1.17.1
22+
go.mongodb.org/mongo-driver/v2 v2.4.0
2223
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
2324
golang.org/x/sync v0.13.0
2425
gopkg.in/natefinch/lumberjack.v2 v2.0.0
@@ -37,10 +38,10 @@ require (
3738
github.com/go-playground/universal-translator v0.18.1 // indirect
3839
github.com/go-playground/validator/v10 v10.26.0 // indirect
3940
github.com/goccy/go-json v0.10.5 // indirect
40-
github.com/golang/snappy v0.0.4 // indirect
41+
github.com/golang/snappy v1.0.0 // indirect
4142
github.com/huandu/go-clone v1.6.0 // indirect
4243
github.com/json-iterator/go v1.1.12 // indirect
43-
github.com/klauspost/compress v1.13.6 // indirect
44+
github.com/klauspost/compress v1.16.7 // indirect
4445
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
4546
github.com/leodido/go-urn v1.4.0 // indirect
4647
github.com/mattn/go-colorable v0.1.13 // indirect

go.sum

Lines changed: 11 additions & 68 deletions
Large diffs are not rendered by default.

internal/keystring/keystring_decoder.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import (
88
"math"
99
"math/bits"
1010

11-
"go.mongodb.org/mongo-driver/bson"
12-
"go.mongodb.org/mongo-driver/bson/primitive"
11+
"go.mongodb.org/mongo-driver/v2/bson"
1312
)
1413

1514
// This is a direct port of the Javascript keystring decoder from
@@ -205,13 +204,13 @@ func readValue(ctype cType, version KeyStringVersion, buf *bufferConsumer) (any,
205204
isNegative := false
206205
switch ctype {
207206
case kMinKey:
208-
return primitive.MinKey{}, nil
207+
return bson.MinKey{}, nil
209208
case kMaxKey:
210-
return primitive.MaxKey{}, nil
209+
return bson.MaxKey{}, nil
211210
case kNullish:
212211
return nil, nil
213212
case kUndefined:
214-
return primitive.Undefined{}, nil
213+
return bson.Undefined{}, nil
215214
case kBoolTrue:
216215
return true, nil
217216
case kBoolFalse:
@@ -221,7 +220,7 @@ func readValue(ctype cType, version KeyStringVersion, buf *bufferConsumer) (any,
221220
if err != nil {
222221
return nil, err
223222
}
224-
return primitive.DateTime(dateTimeAsInt ^ (uint64(1) << 63)), nil
223+
return bson.DateTime(dateTimeAsInt ^ (uint64(1) << 63)), nil
225224
case kTimestamp:
226225
t, err := buf.readUint32BE()
227226
if err != nil {
@@ -231,9 +230,9 @@ func readValue(ctype cType, version KeyStringVersion, buf *bufferConsumer) (any,
231230
if err != nil {
232231
return nil, err
233232
}
234-
return primitive.Timestamp{T: t, I: i}, nil
233+
return bson.Timestamp{T: t, I: i}, nil
235234
case kOID:
236-
var oid primitive.ObjectID
235+
var oid bson.ObjectID
237236
oidSlice, err := buf.readBytes(12)
238237
if err != nil {
239238
return nil, err
@@ -247,7 +246,7 @@ func readValue(ctype cType, version KeyStringVersion, buf *bufferConsumer) (any,
247246
if err != nil {
248247
return nil, err
249248
}
250-
return primitive.JavaScript(str), nil
249+
return bson.JavaScript(str), nil
251250
case kCodeWithScope:
252251
code, err := buf.readCStringWithNuls()
253252
if err != nil {
@@ -257,7 +256,7 @@ func readValue(ctype cType, version KeyStringVersion, buf *bufferConsumer) (any,
257256
if err != nil {
258257
return nil, err
259258
}
260-
return primitive.CodeWithScope{Code: primitive.JavaScript(code), Scope: scope}, nil
259+
return bson.CodeWithScope{Code: bson.JavaScript(code), Scope: scope}, nil
261260
case kBinData:
262261
size8, err := buf.readUint8()
263262
if err != nil {
@@ -279,7 +278,7 @@ func readValue(ctype cType, version KeyStringVersion, buf *bufferConsumer) (any,
279278
if err != nil {
280279
return nil, err
281280
}
282-
return primitive.Binary{Data: data, Subtype: subtype}, nil
281+
return bson.Binary{Data: data, Subtype: subtype}, nil
283282
case kRegEx:
284283
pattern, err := buf.readCString()
285284
if err != nil {
@@ -289,7 +288,7 @@ func readValue(ctype cType, version KeyStringVersion, buf *bufferConsumer) (any,
289288
if err != nil {
290289
return nil, err
291290
}
292-
return primitive.Regex{Pattern: pattern, Options: flags}, nil
291+
return bson.Regex{Pattern: pattern, Options: flags}, nil
293292
case kDBRef:
294293
size, err := buf.readUint32BE()
295294
if err != nil {
@@ -304,9 +303,9 @@ func readValue(ctype cType, version KeyStringVersion, buf *bufferConsumer) (any,
304303
if err != nil {
305304
return nil, err
306305
}
307-
var oid primitive.ObjectID
306+
var oid bson.ObjectID
308307
copy(oid[:], oidBytes)
309-
return primitive.DBPointer{DB: ns, Pointer: oid}, nil // TODO: What happens to non-OID DBRefs?
308+
return bson.DBPointer{DB: ns, Pointer: oid}, nil // TODO: What happens to non-OID DBRefs?
310309
case kObject:
311310
return keystringToBsonPartial(version, buf, modeNamed)
312311
case kArray:

internal/keystring/keystring_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"github.com/stretchr/testify/assert"
88
"github.com/stretchr/testify/require"
9-
"go.mongodb.org/mongo-driver/bson"
9+
"go.mongodb.org/mongo-driver/v2/bson"
1010
)
1111

1212
type TestCase struct {

internal/partitions/bson.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66
"github.com/10gen/migration-verifier/mslices"
77
"github.com/pkg/errors"
88
"github.com/samber/lo"
9-
"go.mongodb.org/mongo-driver/bson"
10-
"go.mongodb.org/mongo-driver/bson/bsontype"
9+
"go.mongodb.org/mongo-driver/v2/bson"
1110
)
1211

1312
// -------------------------------------------------------------------------
@@ -61,7 +60,7 @@ var bsonTypeSortOrder = lo.Flatten(mslices.Of(
6160
),
6261
))
6362

64-
var bsonTypeString = map[bsontype.Type]string{
63+
var bsonTypeString = map[bson.Type]string{
6564
bson.TypeMinKey: "minKey",
6665
bson.TypeNull: "null",
6766
bson.TypeBoolean: "bool",
@@ -91,7 +90,7 @@ var bsonTypeString = map[bsontype.Type]string{
9190
// This is kind of like strings.Cut() but against the sort-ordered list of BSON
9291
// types, except that if the given value is a number or string-like, then other
9392
// “like” types will not be in the returned slices.
94-
func getTypeBracketExcludedBSONTypes(val any) ([]bsontype.Type, []bsontype.Type, error) {
93+
func getTypeBracketExcludedBSONTypes(val any) ([]bson.Type, []bson.Type, error) {
9594
bsonType, _, err := bson.MarshalValue(val)
9695
if err != nil {
9796
return nil, nil, errors.Wrapf(err, "marshaling min value (%v)", val)
@@ -123,10 +122,10 @@ func getTypeBracketExcludedBSONTypes(val any) ([]bsontype.Type, []bsontype.Type,
123122
return earlier, later, nil
124123
}
125124

126-
func typesToStrings(in []bsontype.Type) []string {
125+
func typesToStrings(in []bson.Type) []string {
127126
return lo.Map(
128127
in,
129-
func(t bsontype.Type, _ int) string {
128+
func(t bson.Type, _ int) string {
130129
return bsonTypeString[t]
131130
},
132131
)

0 commit comments

Comments
 (0)