Skip to content

Commit

Permalink
fix(mongodb): Fallback to mongo command if mongosh is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Oct 5, 2023
1 parent b3118d6 commit 83346d1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/database/dialect/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions internal/database/dialect/mongodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 83346d1

Please sign in to comment.