package
2.4.6
Repository: https://github.com/jobaldw/shared.git
Documentation: pkg.go.dev

# README

shared | mongo

This package utilizes the official mongo driver making it simpler to configure and connect to a mongo instance for reading and writing.

How To Use

package main

import (
	"context"

	"github.com/jobaldw/shared/v2/config"
	"github.com/jobaldw/shared/v2/mongo"
)

func main() {

	// Use the shared config.Mongo() struct for mongo client configurations.
	// NOTE: If you use the URI, you will need to user and password url encoding. 
	// Using the Username and Password options will handle the encoding for you.
	conf := config.Mongo{
		Database: "dbName",
		URI:      "bW9uZ28rc3ZyOi8vPHlvdXJNb25nb1VSST4",
		Collections: map[string]string{
			"key1": "value1",
		},
	}

	// Create new mongo client.
	mongoClient, err := mongo.New(conf)
	if err != nil {
		// handle error
	}

	// The GetCollection() gives you the ability to interact with the collection's 
	// CRUD operations.
	key1 := mongoClient.GetCollection("key1")
	key1.FindOne(context.Background(), nil)
}

# Functions

New implements a new mongo object that connects to a database and creates a handle for mongo collections.

# Variables

no collection to read from or write to.
no database has been connected.
no mongo documents are in the result set.

# Structs

Holds the configurations for a mongo connection using the official mongo driver package.