Documentation ¶
Overview ¶
Package mgoutil provides various methods for working with the mgo.v2 package, implementing various oft-used behaviors
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureSession ¶
func EnsureSession(addr string) *mgo.Session
EnsureSession connections to the given addr with a 5 second timeout, sets the session to Safe, sets the mode to PrimaryPreferred, and returns the resulting mgo.Session. If it fails to connect it fatals.
func MustEnsureIndexes ¶
func MustEnsureIndexes(db *mgo.Database, indexes ...Index)
MustEnsureIndexes takes the given indexes and ensure's they are all in place. It will make the calls with Background:true. If any indexes fail a message will be logged and the process will exit
DEPRECATED: Use the MustEnsureIndexes method on SessionHelper instead. This will be removed at some point in the future
NOTE WHEN SWITCHING TO NEW METHOD: the new method does *not* automatically set Background: true like this one does, so be aware of that difference when switching over
Types ¶
type Index ¶
type Index struct { Name string // human readable name for the index, only used for the log entry Keys []string Coll string Unique bool Sparse bool }
Index is used in MustEnsureIndexes to convey all the information needed to ensure a background index
DEPRECATED: MustEnsureIndexes is deprecated, and therefore this type is as well. This will be removed at some point in the future
type SessionHelper ¶
CollectionHelper is a simple helper type which makes it easy to call methods on a Database or Collection safely. It will handle the Copy'ing and Close'ing of the given Session automatically
func (SessionHelper) MustEnsureIndexes ¶
func (s SessionHelper) MustEnsureIndexes(indexes ...mgo.Index)
MustEnsureIndexes takes the given indexes and ensure's they are all in place. If any indexes fail a message will be logged and the process will exit
func (SessionHelper) WithColl ¶
func (s SessionHelper) WithColl(fn func(*mgo.Collection))
WithColl handles calls the given function on an instance of the collection named by the field in the SessionHelper. It will handle Copy'ing and Close'ing the Session object automatically.
func (SessionHelper) WithDB ¶
func (s SessionHelper) WithDB(fn func(*mgo.Database))
WithDB handles calls the given function on an instance of the database named by the field in the SessionHelper. It will handle Copy'ing and Close'ing the Session object automatically.