mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-07-20 22:48:02 +00:00
Drop indexes
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func (a *App) GetIndexes(hostKey, dbKey, collKey string) []bson.M {
|
||||
@ -40,3 +41,25 @@ func (a *App) GetIndexes(hostKey, dbKey, collKey string) []bson.M {
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
func (a *App) DropIndex(hostKey, dbKey, collKey, indexName string) bool {
|
||||
client, ctx, close, err := a.connectToHost(hostKey)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return false
|
||||
}
|
||||
defer close()
|
||||
|
||||
_, err = client.Database(dbKey).Collection(collKey).Indexes().DropOne(ctx, indexName, &options.DropIndexesOptions{})
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Encountered an error while creating index cursor",
|
||||
Message: err.Error(),
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
Reference in New Issue
Block a user