mongo: indexes
This commit is contained in:
parent
1744b94cef
commit
c93b41dcfe
@ -1,11 +1,24 @@
|
||||
package logmower
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
func initializeIndexes(ctx context.Context, col *mongo.Collection) error {
|
||||
ind := col.Indexes()
|
||||
|
||||
// (does not create duplicates)
|
||||
_, err := ind.CreateOne(mongoTimeoutCtx(ctx), mongo.IndexModel{
|
||||
Keys: bson.D{{Key: mongoKeyFileBasename, Value: 1}, {Key: mongoKeyOffset, Value: -1}},
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// when editing, also edit everything in this file!
|
||||
type mLog struct {
|
||||
HostInfo HostInfo
|
||||
|
@ -124,6 +124,11 @@ var App = &cli.App{
|
||||
|
||||
state.db = dbClient.Database(uriParsed.Path).Collection("logs")
|
||||
|
||||
err = initializeIndexes(ctx.Context, state.db)
|
||||
if err != nil {
|
||||
l.Fatal("initializing indexes", zap.Error(err))
|
||||
}
|
||||
|
||||
state.hostInfo, err = getHostInfo(ctx.String("node-name"))
|
||||
if err != nil {
|
||||
l.Fatal("gathering host info", zap.Error(err))
|
||||
|
Loading…
Reference in New Issue
Block a user