Skip to content

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

fix(mongodb): respect query limit using gomongo execute options (#19108)

h3n4la125a84ac1c5
diff --git a/backend/plugin/db/mongodb/mongodb.go b/backend/plugin/db/mongodb/mongodb.go
index af31b1fac3..5727665466 100644
--- a/backend/plugin/db/mongodb/mongodb.go
+++ b/backend/plugin/db/mongodb/mongodb.go
@@ -257,7 +257,11 @@ func (d *Driver) QueryConn(ctx context.Context, _ *sql.Conn, statement string, q
if d.client != nil {
gmClient := gomongo.NewClient(d.client)
var gmResult *gomongo.Result
- gmResult, gomongoErr = gmClient.Execute(ctx, d.databaseName, statement)
+ var opts []gomongo.ExecuteOption
+ if queryContext.Limit > 0 {
+ opts = append(opts, gomongo.WithMaxRows(int64(queryContext.Limit)))
+ }
+ gmResult, gomongoErr = gmClient.Execute(ctx, d.databaseName, statement, opts...)
if gomongoErr == nil {
return d.convertGomongoResult(gmResult, statement, startTime), nil
}
diff --git a/go.mod b/go.mod
index 73eda11c48..478c15c401 100644
--- a/go.mod
+++ b/go.mod
@@ -32,7 +32,7 @@ require (
github.com/beltran/gohive/v2 v2.0.0
github.com/blang/semver/v4 v4.0.0
github.com/bmatcuk/doublestar/v4 v4.9.2
- github.com/bytebase/gomongo v0.0.0-20260121095259-4d0ac7950ed8
+ github.com/bytebase/gomongo v0.0.0-20260122102630-d4856f4d6ca0
github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0
github.com/caarlos0/env/v11 v11.3.1
github.com/cenkalti/backoff/v5 v5.0.3
diff --git a/go.sum b/go.sum
index d02e7bbda6..5e65924468 100644
--- a/go.sum
+++ b/go.sum
@@ -857,8 +857,8 @@ github.com/bytebase/gh-ost2 v1.1.7-0.20251002210738-35e5dddaad7c h1:scJ4ycKuUAaA
github.com/bytebase/gh-ost2 v1.1.7-0.20251002210738-35e5dddaad7c/go.mod h1:X0CGYwIZUnjfrv02/nBlftxqSBMm4mYJzFwiyn2D4d8=
github.com/bytebase/go-mssqldb v0.0.0-20240801091126-3ff3ca07d898 h1:0ggqA9XL4yvtePPvRDRYMed3jtdNk4s0o8AMW8uJPSA=
github.com/bytebase/go-mssqldb v0.0.0-20240801091126-3ff3ca07d898/go.mod h1:2KhUz4GSLcdJGXSJMXAf2BjmakcgoOkNyPpHdGAxRpY=
-github.com/bytebase/gomongo v0.0.0-20260121095259-4d0ac7950ed8 h1:/MFuVj7SR+TQAXtLkt5y72a8JnvKcYITfQOoAhyvbvM=
-github.com/bytebase/gomongo v0.0.0-20260121095259-4d0ac7950ed8/go.mod h1:7aVbtrEx9OpYH+qoeyqdxAVXH5NsBJSbTScD2jt+B0o=
+github.com/bytebase/gomongo v0.0.0-20260122102630-d4856f4d6ca0 h1:jUZGxDJQz1M9e12Lgh6bzFlruSHt7CCDV8Exwg+xIPY=
+github.com/bytebase/gomongo v0.0.0-20260122102630-d4856f4d6ca0/go.mod h1:7aVbtrEx9OpYH+qoeyqdxAVXH5NsBJSbTScD2jt+B0o=
github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0 h1:bJ8NSf2K+pccl5m/wuu97fiYjDwpJH6IzURAq/3XA2U=
github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0/go.mod h1:BEWMfiZtqshdmulKJcIsWb45MUaEvDO4CROcgi8dfFg=
github.com/bytebase/parser v0.0.0-20260121030202-698704919f24 h1:oonTO26orUa4bYk/hQjALiYO1zII+Kzpjg75OnC3VtU=