Categorygithub.com/mywrap/mongodb
modulepackage
0.2.2
Repository: https://github.com/mywrap/mongodb.git
Documentation: pkg.go.dev

# README

MongoDB client

Quick config to connect MongoDB from environment vars.
Wrapped mongodb/mongo-go-driver.

Usage

cfg := Config{Host: "127.0.0.1", Port: "27017", Database: "paave_news"}
client, err := Connect(cfg)
if err != nil {
    log.Fatalf("error Connect: %v", err)
}
ret, err := client.Database(cfg.Database).Collection("TestStruct").
    UpdateOne(context.TODO(),
        bson.M{"_id": "TestKey0"},
        bson.M{"$set": bson.M{"Value": "test value", "UpdatedAt": time.Now()}},
        options.Update().SetUpsert(true),
    )

# Functions

Connect initializes a new MongoDB client (and sends a Ping).
LoadEnvConfig loads config from environment variables: MONGO_HOST, MONGO_PORT, MONGO_ROOT_USERNAME, MONGO_ROOT_PASSWORD, MONGO_DATABASE.

# Structs

Config can be loaded easily by calling func LoadEnvConfig.