mongo: indexes
This commit is contained in:
parent
1744b94cef
commit
c93b41dcfe
@ -1,11 +1,24 @@
|
|||||||
package logmower
|
package logmower
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"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!
|
// when editing, also edit everything in this file!
|
||||||
type mLog struct {
|
type mLog struct {
|
||||||
HostInfo HostInfo
|
HostInfo HostInfo
|
||||||
|
@ -124,6 +124,11 @@ var App = &cli.App{
|
|||||||
|
|
||||||
state.db = dbClient.Database(uriParsed.Path).Collection("logs")
|
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"))
|
state.hostInfo, err = getHostInfo(ctx.String("node-name"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Fatal("gathering host info", zap.Error(err))
|
l.Fatal("gathering host info", zap.Error(err))
|
||||||
|
Loading…
Reference in New Issue
Block a user