// SetupMongoDatabase establishes the connexion with the mongo database
SetupMongoDatabase establishes the connexion with the mongo database
// SetupMongoDatabase establishes the connexion with the mongo database
func (a *API) SetupMongoDatabase() (*mongo.Database, error) {
	uri := "mongodb://"
	if (a.Config.GetString("mongo_db_user") != "") && (a.Config.GetString("mongo_db_password") != "") {
		uri += a.Config.GetString("mongo_db_user") + ":" + a.Config.GetString("mongo_db_password") + "@"
	}
	uri += a.Config.GetString("mongo_db_host")
	clientOptions := options.Client().ApplyURI(uri)
	client, err := mongo.Connect(context.TODO(), clientOptions)
	if err != nil {
		return nil, fmt.Errorf("Mongo client couldn't connect with background context: %v", err)
	}
	database := client.Database(a.Config.GetString("mongo_db_name"))
	a.MongoDatabase = database
	return database, nil
}
func ( a * API ) SetupMongoDatabase ( ) ( * mongo . Database , error ) { uri := " " if ( a . Config . GetString ( " " ) != " " ) && ( a . Config . GetString ( " " ) != " " ) { uri += a . Config . GetString ( " " ) + " " + a . Config . GetString ( " " ) + " " } uri += a . Config . GetString ( " " ) clientOptions := options . Client ( ) . ApplyURI ( uri ) client , err := mongo . Connect ( context . TODO ( ) , clientOptions ) if err != nil { return nil , fmt . Errorf ( " " , err ) } database := client . Database ( a . Config . GetString ( " " ) ) a . MongoDatabase = database return database , nil }
SetupMongoDatabase establishes the connexion with the mongo database
SetupMongoDatabase establishes the connexion with the mongo database
// Connect to MongoDB