-
Notifications
You must be signed in to change notification settings - Fork 63
/
indexes.go
41 lines (37 loc) · 1.1 KB
/
indexes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2021 Kuei-chun Chen. All rights reserved.
package keyhole
import (
"github.com/simagix/keyhole/mdb"
"go.mongodb.org/mongo-driver/mongo"
)
// DuplicateIndexesFromFile duplicate indexes from definitions defined in a file
func DuplicateIndexesFromFile(index *mdb.IndexStats, client *mongo.Client, filename string, isDrop bool) error {
var err error
var databases []mdb.Database
if err = index.SetClusterDetailsFromFile(filename); err != nil {
return err
}
if err = index.CopyIndexes(client, isDrop); err != nil {
return err
}
if databases, err = index.GetIndexes(client); err != nil {
return err
}
index.PrintIndexesOf(databases)
return err
}
// CollectIndexStats collects all indexes stats
func CollectIndexStats(index *mdb.IndexStats, client *mongo.Client, maobiURL string) error {
var err error
var data []byte
var ofile string
var databases []mdb.Database
if databases, err = index.GetIndexes(client); err != nil {
return err
}
index.PrintIndexesOf(databases)
if ofile, data, err = index.OutputBSON(); err != nil {
return err
}
return GenerateMaobiReport(maobiURL, data, ofile)
}