From 83346d1c51189319b107800478436ad51b535f40 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Thu, 5 Oct 2023 00:53:23 -0500 Subject: [PATCH] fix(mongodb): Fallback to `mongo` command if `mongosh` is not available --- internal/database/dialect/mongodb.go | 2 +- internal/database/dialect/mongodb_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/database/dialect/mongodb.go b/internal/database/dialect/mongodb.go index e86c4424..0091dafc 100644 --- a/internal/database/dialect/mongodb.go +++ b/internal/database/dialect/mongodb.go @@ -79,7 +79,7 @@ func (db MongoDB) AuthenticationDatabase(c config.Global) string { func (db MongoDB) ExecCommand(conf config.Exec) *command.Builder { cmd := command.NewBuilder( - "mongosh", + command.Raw(`"$(which mongosh || which mongo)"`), "--host="+conf.Host, "--username="+conf.Username, "--password="+conf.Password, diff --git a/internal/database/dialect/mongodb_test.go b/internal/database/dialect/mongodb_test.go index 49db62b4..861b7b70 100644 --- a/internal/database/dialect/mongodb_test.go +++ b/internal/database/dialect/mongodb_test.go @@ -152,17 +152,17 @@ func TestMongoDB_ExecCommand(t *testing.T) { { "default", args{config.Exec{Global: config.Global{Host: "1.1.1.1", Database: "d", Username: "u", Password: "p"}}}, - command.NewBuilder("mongosh", "--host=1.1.1.1", "--username=u", "--password=p", "--authenticationDatabase=d", "d"), + command.NewBuilder(command.Raw(`"$(which mongosh || which mongo)"`), "--host=1.1.1.1", "--username=u", "--password=p", "--authenticationDatabase=d", "d"), }, { "disable-headers", args{config.Exec{DisableHeaders: true, Global: config.Global{Host: "1.1.1.1", Database: "d", Username: "u", Password: "p"}}}, - command.NewBuilder("mongosh", "--host=1.1.1.1", "--username=u", "--password=p", "--authenticationDatabase=d", "--quiet", "d"), + command.NewBuilder(command.Raw(`"$(which mongosh || which mongo)"`), "--host=1.1.1.1", "--username=u", "--password=p", "--authenticationDatabase=d", "--quiet", "d"), }, { "command", args{config.Exec{Command: "show databases", Global: config.Global{Host: "1.1.1.1", Database: "d", Username: "u", Password: "p"}}}, - command.NewBuilder("mongosh", "--host=1.1.1.1", "--username=u", "--password=p", "--authenticationDatabase=d", "--eval=show databases", "d"), + command.NewBuilder(command.Raw(`"$(which mongosh || which mongo)"`), "--host=1.1.1.1", "--username=u", "--password=p", "--authenticationDatabase=d", "--eval=show databases", "d"), }, } for _, tt := range tests {