Documentation ¶
Overview ¶
Package mongo implements a Mongo instance that connects to a database and allows interactions with the datasource.
All functions that require a context to be passed should be given one from the service handler request to correctly handle cancellations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNoCollections = errors.New("no configured collections") // no collection to read from or write to ErrNoDatabase = errors.New("no database found") // no database has been connected ErrNoDocuments = errors.New("no documents in result") // no mongo documents are in the result set )
Functions ¶
This section is empty.
Types ¶
type Mongo ¶
type Mongo struct { // host or host:port of the mongo uri Host string // mongo database name Name string // username/password information for uri authentication User string // handles to a MongoDB collection Collections map[string]*mongo.Collection // handle to a MongoDB database Database *mongo.Database // representation of a parsed URL (technically, a URI reference) URI *url.URL }
Holds the configurations for a mongo connection using the official mongo driver package.
func New ¶
New implements a new mongo object that connects to a database and creates a handle for mongo collections.
func (*Mongo) GetCollection ¶
func (m *Mongo) GetCollection(key string) *mongo.Collection
GetCollection retrieves a mongo collection object.
Click to show internal directories.
Click to hide internal directories.