- update mongo

master v1.0.87
李光春 2 years ago
parent f38cafd8f7
commit 4df2eab876

@ -115,6 +115,9 @@ func NewApiClient(config *ApiClientConfig) (*ApiClient, error) {
// 创建时间序列集合
c.mongoCreateCollection(ctx)
// 创建索引
c.mongoCreateIndexes(ctx)
c.mongoConfig.stats = true
}

@ -47,6 +47,21 @@ func (c *ApiClient) mongoCreateCollection(ctx context.Context) {
}
}
// 创建索引
func (c *ApiClient) mongoCreateIndexes(ctx context.Context) {
indexes, err := c.mongoClient.Database(c.mongoConfig.databaseName).Collection(c.mongoConfig.collectionName).CreateManyIndexes(ctx, []mongo.IndexModel{
{
Keys: bson.D{{
Key: "log_time",
Value: -1,
}},
}})
if err != nil {
c.zapLog.WithTraceId(ctx).Sugar().Errorf("创建索引:%s", err)
}
c.zapLog.WithTraceId(ctx).Sugar().Infof("创建索引:%s", indexes)
}
// 记录日志
func (c *ApiClient) mongoRecord(ctx context.Context, mongoLog apiMongolLog) (err error) {

Loading…
Cancel
Save