1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-18 13:07:58 +00:00

Connect to mongosh using the right credentials

This commit is contained in:
Romein van Buren 2023-06-24 11:05:19 +02:00
parent 3893c8dd06
commit 958a0197a4
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49

View File

@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"path"
"strings"
"github.com/google/uuid"
"github.com/wailsapp/wails/v2/pkg/runtime"
@ -55,7 +56,13 @@ func (a *App) ExecuteShellScript(hostKey, dbKey, collKey, script string) (result
return
}
script = fmt.Sprintf("db = connect('%s');\n\n%s", host.URI, script)
connstr := host.URI
if !strings.HasSuffix(connstr, "/") {
connstr = connstr + "/"
}
connstr = connstr + dbKey
script = fmt.Sprintf("db = connect('%s');\ncoll = db.getCollection('%s');\n\n%s", connstr, collKey, script)
if err := os.WriteFile(fname, []byte(script), os.ModePerm); err != nil {
runtime.LogWarningf(a.ctx, "Shell: failed to write script to %s", err.Error())
@ -64,7 +71,7 @@ func (a *App) ExecuteShellScript(hostKey, dbKey, collKey, script string) (result
return
}
cmd := exec.Command("mongosh", "--file", fname)
cmd := exec.Command("mongosh", "--file", fname, connstr)
stdout, err := cmd.Output()
if exiterr, ok := err.(*exec.ExitError); ok {