mongoHelper

package
v4.1.12+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package mongoHelper provides a system of functions that wraps selected mgo functions, except that they will retry once in case of an error. All of these functions are mimics of the ones on mgo.Collection, except that they will reconnect and try again in case the request returns EOF, which is how mgo signals a dropped connection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type M

type M struct {
	Key      string
	Url      string // TODO(epettis): this should be named URL
	DbName   string
	CollName string
	Sess     *mgo.Session
	Coll     *mgo.Collection
	Reconn   Reconnector
	Log      log.StdLogger
}

M provides a place to track the Mongo session and collection, and a way to call the client's connect function when the session dies. Key is a unique identifier (in case you're managing more than one of these)

func (*M) Connect

func (m *M) Connect() error

Connect will connect to the MongoDB server(s) specified in the URL. It also supports connections where ssl is enabled.

func (*M) FindAll

func (m *M) FindAll(query interface{}, destp interface{}) error

FindAll acts like mgo.Find().All(), but will retry once if the connection fails

func (*M) FindAllWithLimit

func (m *M) FindAllWithLimit(query interface{}, destp interface{}, limit int) error

FindAllWithLimit acts like mgo.Find().Limit().All(), but will retry once if the connection fails

func (*M) FindAllWithProjectionSkipLimit

func (m *M) FindAllWithProjectionSkipLimit(query interface{}, destp interface{}, projection interface{}, skip int, limit int) error

FindAllWithProjectionSkipLimit acts like mgo.Find().Select().Skip().Limit().All(), but will retry once if the connection fails

func (*M) FindAllWithSkipLimit

func (m *M) FindAllWithSkipLimit(query interface{}, destp interface{}, skip int, limit int) error

FindAllWithSkipLimit acts like mgo.Find().Skip().Limit().All(), but will retry once if the connection fails

func (*M) FindOne

func (m *M) FindOne(query interface{}, destp interface{}) error

FindOne acts like mgo.Find().One(), but will retry once if the connection fails

func (*M) FindOneID

func (m *M) FindOneID(id string, destp interface{}) error

FindOneID acts like mgo.FindId().One(), but will retry once if the connection fails

func (*M) Insert

func (m *M) Insert(doc interface{}) error

Insert acts like mgo.Insert(), and will retry once if the connection fails

func (*M) PipeAll

func (m *M) PipeAll(pipeline interface{}, destp interface{}) error

PipeAll acts like mgo.Pipe().All(), but will retry once if the connection fails

func (*M) Remove

func (m *M) Remove(selector interface{}) error

Remove acts like mgo.Remove(), and will retry once if the connection fails

func (*M) Update

func (m *M) Update(selector interface{}, update interface{}) error

Update acts like mgo.Update(), and will retry once if the connection fails

func (*M) Upsert

func (m *M) Upsert(selector interface{}, update interface{}) (*mgo.ChangeInfo, error)

Upsert acts like mgo.Upsert(), and will retry once if the connection fails

type Reconnector

type Reconnector interface {
	Reconnect(m *M) error
}

Reconnector is the interface that client packages have to provide in order to work with this system. They should pass themselves in as the Reconn element of the M struct; the reconnect function should re-establish any special connection parameters (like safe mode, indices, etc)

Jump to

Keyboard shortcuts

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