mg

package
v0.0.0-...-38cdf9c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func C

func C(collectionName string) *mongo.Collection

C - get a handle to collection in the default database, single letter name to have nice way to transition from mgo

func CollectionWithDB

func CollectionWithDB(db, coll string) *mongo.Collection

CollectionWithDB - gives a reference to a collection in given database

func Connect

func Connect(gtx context.Context, uri string, defaultDB string) error

Connect - connects to a mongoDB instance or a cluster based on the the options provided

func ConnectWithOpts

func ConnectWithOpts(gtx context.Context, opts *ConnOpts) error

func ReadAllAndClose

func ReadAllAndClose(
	gtx context.Context,
	cur *mongo.Cursor,
	out interface{}) error

ReadAllAndClose - reads all data from the cursor and closes it

func ReadOneAndClose

func ReadOneAndClose(
	gtx context.Context,
	cur *mongo.Cursor,
	out interface{}) error

ReadOneAndClose - reads one data item from the cursor and closes it

func WithMongo

func WithMongo(defaultDb string, cmd *cli.Command) *cli.Command

Types

type ConnOpts

type ConnOpts struct {
	Host     string `json:"host"`
	Port     int    `json:"port"`
	User     string `json:"user"`
	Password string `json:"password"`
	DbName   string `json:"dbName"`
}

ConnOpts - options for connecting to a mongodb instance

type ConnType

type ConnType string

ConnType - type of cluster to connect to

const ReplicaSet ConnType = "ReplicaSet"

ReplicaSet - A replica set cluster

const Sharded ConnType = "Sharded"

Sharded - Sharded database

const Single ConnType = "Single"

Single - No cluster, single instance

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL