Documentation ¶
Overview ¶
MongoHelper provides a system of functions that wrapper 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 ¶
- type M
- func (m *M) Connect() error
- func (m *M) FindAll(query interface{}, destp interface{}) error
- func (m *M) FindAllWithLimit(query interface{}, destp interface{}, limit int) error
- func (m *M) FindAllWithProjectionSkipLimit(query interface{}, destp interface{}, projection interface{}, skip int, ...) error
- func (m *M) FindAllWithSkipLimit(query interface{}, destp interface{}, skip int, limit int) error
- func (m *M) FindOne(query interface{}, destp interface{}) error
- func (m *M) FindOneID(id string, destp interface{}) error
- func (m *M) Insert(doc interface{}) error
- func (m *M) PipeAll(pipeline interface{}, destp interface{}) error
- func (m *M) Remove(selector interface{}) error
- func (m *M) Update(selector interface{}, update interface{}) error
- func (m *M) Upsert(selector interface{}, update interface{}) (*mgo.ChangeInfo, error)
- type Reconnector
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 DbName string CollName string Sess *mgo.Session Coll *mgo.Collection Reconn Reconnector Log log.StdLogger }
This 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) FindAllWithLimit ¶
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 ¶
FindAllWithSkipLimit acts like mgo.Find().Skip().Limit().All(), but will retry once if the connection fails
func (*M) FindOneID ¶
FindOneID acts like mgo.FindId().One(), but will retry once if the connection fails
type Reconnector ¶
Connector 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)