mg

package
v0.0.0-...-8e695b4 Latest Latest
Warning

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

Go to latest
Published: May 1, 2021 License: MIT Imports: 13 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, opts *ConnOpts) error

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

func Decode

func Decode(res *mongo.SingleResult, out interface{}) error

Decode - convenience method for decoding mongo.SingleResult

func GenerateSelector

func GenerateSelector(
	filter *teak.Filter) (selector bson.M)

GenerateSelector - creates mongodb query for a generic filter

func GetSort

func GetSort(sortField string) bson.D

GetSort - get sort statement for the field

func NewDefaultApp

func NewDefaultApp(
	name string,
	appVersion teak.Version,
	apiVersion int,
	desc string) *teak.App

NewDefaultApp - creates a new app with MongoDB based storage providers

func NewStorage

func NewStorage() teak.DataStorage

NewStorage - creates a new mongodb based data storage implementation

func NewUserStorage

func NewUserStorage() teak.UserStorage

NewUserStorage - creates a new user storage based on mongodb

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 SetDefaultDB

func SetDefaultDB(defDB string)

SetDefaultDB - sets the default DB

Types

type ConnOpts

type ConnOpts struct {
	URLs     []string `json:"uri"`
	Type     ConnType `json:"type"`
	User     string   `json:"user"`
	Password string   `json:"password"`
}

ConnOpts - options for connecting to a mongodb instance

func (*ConnOpts) String

func (co *ConnOpts) String() string

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