Skip to content

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

fix: sleepy mongo needs some rest (#9494)

Danny Xu819d763c5460
diff --git a/backend/plugin/db/mongodb/mongodb.go b/backend/plugin/db/mongodb/mongodb.go
index dcc371e4fa..a42fc05399 100644
--- a/backend/plugin/db/mongodb/mongodb.go
+++ b/backend/plugin/db/mongodb/mongodb.go
@@ -179,13 +179,17 @@ func (driver *Driver) QueryConn(ctx context.Context, _ *sql.Conn, statement stri
// 1. Query always short, so it's safe to execute in the command line.
// 2. We cannot catch the output if we use the --file option.
+ // When you see here, it's probable that your mongosh output has been truncated. Errrrrh!
+ // It appears that the truncation occurs specifically within a Linux container, while everything functions as expected on MacOS.
+ // This might be due to the surprising Javascript async behavior or unflushed buffer.
+ // We put a sleep(0) for the eval() to wait for its completion.
evalArg := statement
if simpleStatement {
limit := ""
if queryContext.Limit > 0 {
limit = fmt.Sprintf(".slice(0, %d)", queryContext.Limit)
}
- evalArg = fmt.Sprintf("a = %s; if (typeof a.toArray === 'function') {print(EJSON.stringify(a.toArray()%s))} else {print(EJSON.stringify(a))}", strings.TrimRight(statement, " \t\n\r\f;"), limit)
+ evalArg = fmt.Sprintf("a = %s; if (typeof a.toArray === 'function') {print(EJSON.stringify(a.toArray()%s)); sleep(0);} else {print(EJSON.stringify(a)); sleep(0);}", strings.TrimRight(statement, " \t\n\r\f;"), limit)
}
mongoshArgs := []string{
connectionURI,
diff --git a/backend/server/minimal.go b/backend/server/minimal.go
index e29f6c3d4a..1dd8280261 100644
--- a/backend/server/minimal.go
+++ b/backend/server/minimal.go
@@ -4,6 +4,7 @@ import (
// This includes the first-class database, Postgres.
// Drivers.
+ _ "github.com/bytebase/bytebase/backend/plugin/db/mongodb"
_ "github.com/bytebase/bytebase/backend/plugin/db/pg"
// Parsers.
diff --git a/backend/server/ultimate.go b/backend/server/ultimate.go
index 447e17a387..dcacfaabc5 100644
--- a/backend/server/ultimate.go
+++ b/backend/server/ultimate.go
@@ -6,7 +6,6 @@ import (
// Drivers.
_ "github.com/bytebase/bytebase/backend/plugin/db/clickhouse"
_ "github.com/bytebase/bytebase/backend/plugin/db/dm"
- _ "github.com/bytebase/bytebase/backend/plugin/db/mongodb"
_ "github.com/bytebase/bytebase/backend/plugin/db/mssql"
_ "github.com/bytebase/bytebase/backend/plugin/db/oracle"
_ "github.com/bytebase/bytebase/backend/plugin/db/redis"