package
1.0.0
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/config"
	"github.com/jobaldw/shared/mongo"
)

func main() {

	// Use the shared config.Mongo() struct for mongo client configurations.
	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

There needs to be collections to read and write from the database.
No database has been connected.
This error will occur is no mongo documents are in the result set based on the CRUD operation.

# Structs

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