package app import ( "fmt" "github.com/wailsapp/wails/v2/pkg/runtime" "go.mongodb.org/mongo-driver/bson" ) func (a *App) OpenCollection(hostKey, dbKey, collKey string) (result bson.M) { client, ctx, close, err := a.connectToHost(hostKey) if err != nil { fmt.Println(err.Error()) return nil } command := bson.M{"collStats": collKey} err = client.Database(dbKey).RunCommand(ctx, command).Decode(&result) if err != nil { fmt.Println(err.Error()) runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{ Type: runtime.ErrorDialog, Title: "Could not retrieve collection list for " + dbKey, Message: err.Error(), }) return nil } defer close() return result } func (a *App) DropCollection(hostKey, dbKey, collKey string) bool { sure, _ := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{ Title: "Confirm", Message: "Are you sure you want to drop " + collKey + "?", Buttons: []string{"Yes", "No"}, DefaultButton: "Yes", CancelButton: "No", }) if sure != "Yes" { return false } client, ctx, close, err := a.connectToHost(hostKey) if err != nil { fmt.Println(err.Error()) return false } err = client.Database(dbKey).Collection(collKey).Drop(ctx) if err != nil { fmt.Println(err.Error()) runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{ Type: runtime.ErrorDialog, Title: "Could not drop " + dbKey, Message: err.Error(), }) return false } defer close() return true }