switch to mongodb uri instead of host/username/password
This commit is contained in:
@@ -2,6 +2,7 @@ package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
@@ -17,6 +18,7 @@ type MongoDBStorage struct {
|
||||
|
||||
func NewMongoDBStorage(cfg *viper.Viper) (MongoDBStorage, error) {
|
||||
var (
|
||||
mongodb_uri = cfg.GetString("storage.db.mongodb.uri")
|
||||
mongodb_host = cfg.GetString("storage.db.mongodb.host")
|
||||
mongodb_port = cfg.GetString("storage.db.mongodb.port")
|
||||
mongodb_dbname = cfg.GetString("storage.db.mongodb.db_name")
|
||||
@@ -24,7 +26,11 @@ func NewMongoDBStorage(cfg *viper.Viper) (MongoDBStorage, error) {
|
||||
mongodb_proofs = cfg.GetString("storage.db.mongodb.collections.proofs")
|
||||
)
|
||||
|
||||
client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://" + mongodb_host + ":" + mongodb_port))
|
||||
if mongodb_uri == "" {
|
||||
mongodb_uri = fmt.Sprintf("mongodb://%s:%s/%s", mongodb_host, mongodb_port, mongodb_dbname)
|
||||
}
|
||||
|
||||
client, err := mongo.NewClient(options.Client().ApplyURI(mongodb_uri))
|
||||
if err != nil {
|
||||
return MongoDBStorage{}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user