diff --git a/internal/database/dialect/mongodb.go b/internal/database/dialect/mongodb.go index 277b2491..0d9bbda4 100644 --- a/internal/database/dialect/mongodb.go +++ b/internal/database/dialect/mongodb.go @@ -71,6 +71,7 @@ func (MongoDB) ExecCommand(conf config.Exec) *command.Builder { "--host=127.0.0.1", "--username="+conf.Username, "--password="+conf.Password, + "--authenticationDatabase=admin", ) if conf.DisableHeaders { cmd.Push("--quiet") @@ -91,6 +92,7 @@ func (MongoDB) DumpCommand(conf config.Dump) *command.Builder { "--host=127.0.0.1", "--username="+conf.Username, "--password="+conf.Password, + "--authenticationDatabase=admin", ) if conf.Database != "" { cmd.Push("--db=" + conf.Database) @@ -114,6 +116,7 @@ func (MongoDB) RestoreCommand(conf config.Restore, inputFormat sqlformat.Format) "--host=127.0.0.1", "--username="+conf.Username, "--password="+conf.Password, + "--authenticationDatabase=admin", ) if conf.Database != "" { if conf.Clean { diff --git a/internal/database/dialect/mongodb_test.go b/internal/database/dialect/mongodb_test.go index 0524bb9d..291e65d0 100644 --- a/internal/database/dialect/mongodb_test.go +++ b/internal/database/dialect/mongodb_test.go @@ -111,27 +111,27 @@ func TestMongoDB_DumpCommand(t *testing.T) { { "default", args{config.Dump{Global: config.Global{Database: "d", Username: "u", Password: "p"}}}, - command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d"), + command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d"), }, { "clean", args{config.Dump{Clean: true, Global: config.Global{Database: "d", Username: "u", Password: "p"}}}, - command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d"), + command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d"), }, { "tables", args{config.Dump{Tables: []string{"table1"}, Global: config.Global{Database: "d", Username: "u", Password: "p"}}}, - command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d", "--collection=table1"), + command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d", "--collection=table1"), }, { "exclude-table", args{config.Dump{ExcludeTable: []string{"table1", "table2"}, Global: config.Global{Database: "d", Username: "u", Password: "p"}}}, - command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d", "--excludeCollection=table1", "--excludeCollection=table2"), + command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d", "--excludeCollection=table1", "--excludeCollection=table2"), }, { "quiet", args{config.Dump{Global: config.Global{Database: "d", Username: "u", Password: "p", Quiet: true}}}, - command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d", "--quiet"), + command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d", "--quiet"), }, } for _, tt := range tests { @@ -156,17 +156,17 @@ func TestMongoDB_ExecCommand(t *testing.T) { { "default", args{config.Exec{Global: config.Global{Database: "d", Username: "u", Password: "p"}}}, - command.NewBuilder("mongosh", "--host=127.0.0.1", "--username=u", "--password=p", "d"), + command.NewBuilder("mongosh", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "d"), }, { "disable-headers", args{config.Exec{DisableHeaders: true, Global: config.Global{Database: "d", Username: "u", Password: "p"}}}, - command.NewBuilder("mongosh", "--host=127.0.0.1", "--username=u", "--password=p", "--quiet", "d"), + command.NewBuilder("mongosh", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--quiet", "d"), }, { "command", args{config.Exec{Command: "show databases", Global: config.Global{Database: "d", Username: "u", Password: "p"}}}, - command.NewBuilder("mongosh", "--host=127.0.0.1", "--username=u", "--password=p", "--eval=show databases", "d"), + command.NewBuilder("mongosh", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--eval=show databases", "d"), }, } for _, tt := range tests { @@ -311,27 +311,27 @@ func TestMongoDB_RestoreCommand(t *testing.T) { { "gzip", args{config.Restore{Global: config.Global{Database: "d", Username: "u", Password: "p"}}, sqlformat.Gzip}, - command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d"), + command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d"), }, { "plain", args{config.Restore{Global: config.Global{Database: "d", Username: "u", Password: "p"}}, sqlformat.Plain}, - command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d"), + command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d"), }, { "custom", args{config.Restore{Global: config.Global{Database: "d", Username: "u", Password: "p"}}, sqlformat.Custom}, - command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d"), + command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d"), }, { "clean", args{config.Restore{Clean: true, Global: config.Global{Database: "d", Username: "u", Password: "p"}}, sqlformat.Gzip}, - command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--drop", "--db=d"), + command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--drop", "--db=d"), }, { "quiet", args{config.Restore{Global: config.Global{Database: "d", Username: "u", Password: "p", Quiet: true}}, sqlformat.Gzip}, - command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d", "--quiet"), + command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--authenticationDatabase=admin", "--db=d", "--quiet"), }, } for _, tt := range tests {