+7
-8
@@ -4,11 +4,12 @@ import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
"valera/internal/config"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
|
||||
"valera/internal/config"
|
||||
)
|
||||
|
||||
type DB struct {
|
||||
@@ -18,14 +19,12 @@ type DB struct {
|
||||
}
|
||||
|
||||
func NewDB(
|
||||
mongoURL string,
|
||||
dbName string,
|
||||
cfg *config.AppConfig,
|
||||
) (*DB, error) {
|
||||
ctx := context.Background()
|
||||
opt := options.Client().
|
||||
ApplyURI(mongoURL).
|
||||
ApplyURI(cfg.MongoConfig.URL).
|
||||
SetMinPoolSize(10)
|
||||
cfg := config.NewConfig(mongoURL, dbName)
|
||||
|
||||
client, err := mongo.Connect(ctx, opt)
|
||||
if err != nil {
|
||||
@@ -33,9 +32,9 @@ func NewDB(
|
||||
}
|
||||
|
||||
return &DB{
|
||||
chatsColection: client.Database(dbName).Collection(cfg.ChatsCollectionName),
|
||||
workoutsColection: client.Database(dbName).Collection(cfg.WorkoutsCollectionName),
|
||||
caloriesColection: client.Database(dbName).Collection(cfg.CaloriesCollectionName),
|
||||
chatsColection: client.Database(cfg.MongoConfig.DBName).Collection(cfg.MongoConfig.ChatsCollectionName),
|
||||
workoutsColection: client.Database(cfg.MongoConfig.DBName).Collection(cfg.MongoConfig.WorkoutsCollectionName),
|
||||
caloriesColection: client.Database(cfg.MongoConfig.DBName).Collection(cfg.MongoConfig.CaloriesCollectionName),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user