Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(deps): update module go.mongodb.org/mongo-driver/v2 to v2.9.3 (#21374)

renovate[bot]e646dd66abc8
diff --git a/backend/common/testcontainer/testcontainer.go b/backend/common/testcontainer/testcontainer.go
index 535ba83234..4c9e0c0345 100644
--- a/backend/common/testcontainer/testcontainer.go
+++ b/backend/common/testcontainer/testcontainer.go
@@ -355,10 +355,16 @@ func getTiDBContainer(ctx context.Context) (*Container, error) {
// getMongoDBContainer starts MongoDB, which has no database/sql driver: its
// tests open the Mongo driver themselves from the container's credentials.
+//
+// The image is pinned to the oldest MongoDB release Bytebase supports
+// (mongodb.MinSupportedServerVersion), so that a driver upgrade which raises the
+// floor above it fails this suite instead of reaching customers. Importing that
+// constant here would invert the dependency between the harness and the plugin,
+// so the two are kept in step by hand.
func getMongoDBContainer(ctx context.Context) (*Container, error) {
const user, password = "testuser", "testpass"
return start(ctx, testcontainers.ContainerRequest{
- Image: "mongo:5",
+ Image: "mongo:4.4",
Env: map[string]string{
"MONGO_INITDB_ROOT_USERNAME": user,
"MONGO_INITDB_ROOT_PASSWORD": password,
diff --git a/backend/plugin/db/mongodb/mongodb.go b/backend/plugin/db/mongodb/mongodb.go
index f225a03c0f..36f183f42a 100644
--- a/backend/plugin/db/mongodb/mongodb.go
+++ b/backend/plugin/db/mongodb/mongodb.go
@@ -75,14 +75,32 @@ func (d *Driver) Close(ctx context.Context) error {
return nil
}
+// MinSupportedServerVersion is the oldest MongoDB release the driver in go.mod
+// accepts. The driver enforces it by wire version while selecting a server and
+// refuses anything older, so this constant tracks go.mod's driver and nothing
+// else: raising it is a breaking change for existing instances.
+const MinSupportedServerVersion = "4.4"
+
// Ping pings the database.
func (d *Driver) Ping(ctx context.Context) error {
if err := d.client.Ping(ctx, nil); err != nil {
- return errors.Wrap(err, "failed to ping MongoDB")
+ return errors.Wrap(annotateUnsupportedServerVersion(err), "failed to ping MongoDB")
}
return nil
}
+// annotateUnsupportedServerVersion names the oldest supported release when the
+// driver refused the server for being too old, because the driver's own message
+// reports only a wire version number. The driver returns that refusal as a plain
+// error from server selection rather than a distinguishable type, so matching its
+// text is the only way to recognize it; any other error is returned unchanged.
+func annotateUnsupportedServerVersion(err error) error {
+ if err == nil || !strings.Contains(err.Error(), "wire version") {
+ return err
+ }
+ return errors.Wrapf(err, "MongoDB %s or later is required", MinSupportedServerVersion)
+}
+
// GetDB gets the database.
func (*Driver) GetDB() *sql.DB {
return nil
diff --git a/backend/plugin/db/mongodb/mongodb_test.go b/backend/plugin/db/mongodb/mongodb_test.go
index 801c61e4c2..b397ab1423 100644
--- a/backend/plugin/db/mongodb/mongodb_test.go
+++ b/backend/plugin/db/mongodb/mongodb_test.go
@@ -8,6 +8,7 @@ import (
"time"
"github.com/google/go-cmp/cmp"
+ "github.com/pkg/errors"
"github.com/stretchr/testify/require"
"go.mongodb.org/mongo-driver/v2/bson"
"google.golang.org/protobuf/testing/protocmp"
@@ -557,3 +558,19 @@ func TestQueryConnExplain(t *testing.T) {
})
require.ErrorContains(t, err, "insertOne")
}
+
+func TestAnnotateUnsupportedServerVersion(t *testing.T) {
+ // Copied verbatim from the driver's compatibility error, which is what the
+ // annotation matches on: reword this and it stops being the case under test.
+ refused := errors.New("server at 10.0.0.1:27017 reports wire version 8, but this version of the Go driver requires at least 9 (MongoDB 4.4)")
+
+ annotated := annotateUnsupportedServerVersion(refused)
+ require.ErrorContains(t, annotated, "MongoDB "+MinSupportedServerVersion+" or later is required")
+ require.ErrorContains(t, annotated, "reports wire version 8")
+ require.ErrorIs(t, annotated, refused)
+
+ require.NoError(t, annotateUnsupportedServerVersion(nil))
+
+ authFailure := errors.New("auth error: sasl conversation error")
+ require.Equal(t, authFailure, annotateUnsupportedServerVersion(authFailure))
+}
diff --git a/backend/plugin/db/mongodb/sync.go b/backend/plugin/db/mongodb/sync.go
index fcf0f20f8e..ce1ce15017 100644
--- a/backend/plugin/db/mongodb/sync.go
+++ b/backend/plugin/db/mongodb/sync.go
@@ -263,7 +263,7 @@ func (d *Driver) getVersion(ctx context.Context) (string, error) {
var commandResult bson.M
command := bson.D{{Key: "buildInfo", Value: 1}}
if err := database.RunCommand(ctx, command).Decode(&commandResult); err != nil {
- return "", errors.Wrap(err, "cannot run buildInfo command")
+ return "", errors.Wrap(annotateUnsupportedServerVersion(err), "cannot run buildInfo command")
}
version, ok := commandResult["version"]
if !ok {
diff --git a/go.mod b/go.mod
index af30b19667..107e5f4991 100644
--- a/go.mod
+++ b/go.mod
@@ -100,7 +100,7 @@ require (
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78
github.com/yterajima/go-sitemap v0.4.0
github.com/zeebo/xxh3 v1.1.0
- go.mongodb.org/mongo-driver/v2 v2.8.0
+ go.mongodb.org/mongo-driver/v2 v2.9.3
go.uber.org/multierr v1.11.0
golang.org/x/crypto v0.58.0
golang.org/x/net v0.62.0
diff --git a/go.sum b/go.sum
index c3a6758aee..058d4b9ef7 100644
--- a/go.sum
+++ b/go.sum
@@ -1053,8 +1053,8 @@ go.etcd.io/etcd/client/pkg/v3 v3.5.15 h1:fo0HpWz/KlHGMCC+YejpiCmyWDEuIpnTDzpJLB5
go.etcd.io/etcd/client/pkg/v3 v3.5.15/go.mod h1:mXDI4NAOwEiszrHCb0aqfAYNCrZP4e9hRca3d1YK8EU=
go.etcd.io/etcd/client/v3 v3.5.15 h1:23M0eY4Fd/inNv1ZfU3AxrbbOdW79r9V9Rl62Nm6ip4=
go.etcd.io/etcd/client/v3 v3.5.15/go.mod h1:CLSJxrYjvLtHsrPKsy7LmZEE+DK2ktfd2bN4RhBMwlU=
-go.mongodb.org/mongo-driver/v2 v2.8.0 h1:CxWDGQYY8QQwNjAl/aq2sfWakdnWZynnqJ9F4DhHbP8=
-go.mongodb.org/mongo-driver/v2 v2.8.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
+go.mongodb.org/mongo-driver/v2 v2.9.3 h1:wyiWaPGYaFqRmhjNOXwlK6Cu8Qf35zFH4euH2NBBj34=
+go.mongodb.org/mongo-driver/v2 v2.9.3/go.mod h1:SHKN0IWkKmEVGHLjXnni6s4wPKX4v86FTgOeJJFuXcA=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=