Documentation ¶
Overview ¶
Package db provides tools for using MongoDB databases. However, it wraps mgo types in interfaces that the anser/mocks package provides mocked implementations of for testing facility.
In general, these types are fully functional for most application uses, but do not expose some of the configurability that the mgo equivalents do.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResolveCursorOne ¶
ResolveCursorOne decodes the first result in a cursor, for use in "FindOne" cases.
func ResultsNotFound ¶
Types ¶
type Bulk ¶
type Bulk interface { Insert(...interface{}) Remove(...interface{}) RemoveAll(...interface{}) Update(...interface{}) UpdateAll(...interface{}) Upsert(...interface{}) Unordered() Run() (*BulkResult, error) }
type BulkResult ¶
type Change ¶
type Change struct { Update interface{} // The update document Upsert bool // Whether to insert in case the document isn't found Remove bool // Whether to remove the document found rather than updating ReturnNew bool // Should the modified document be returned rather than the old one }
Change represents the options that you can pass to the findAndModify operation.
type ChangeInfo ¶
type ChangeInfo struct { Updated int // Number of existing documents updated Removed int // Number of documents removed UpsertedId interface{} // Upserted _id field, when not explicitly provided }
ChangeInfo represents the data returned by Update and Upsert documents. This type mirrors the mgo type.
type Collection ¶
type Collection interface { DropCollection() error Pipe(interface{}) Results Find(interface{}) Query FindId(interface{}) Query Count() (int, error) Insert(...interface{}) error Upsert(interface{}, interface{}) (*ChangeInfo, error) UpsertId(interface{}, interface{}) (*ChangeInfo, error) Update(interface{}, interface{}) error UpdateId(interface{}, interface{}) error UpdateAll(interface{}, interface{}) (*ChangeInfo, error) Remove(interface{}) error RemoveId(interface{}) error RemoveAll(interface{}) (*ChangeInfo, error) Bulk() Bulk }
Collection provides access to the common query functionality of the mgo.Collection type.
type CombinedCloser ¶
type CombinedCloser struct { Iterator // contains filtered or unexported fields }
func (CombinedCloser) Close ¶
func (c CombinedCloser) Close() error
type Database ¶
type Database interface { Name() string C(string) Collection DropDatabase() error }
Database provides a very limited subset of the mgo.DB type.
type Document ¶
type Document map[string]interface{}
Document is, like bson.M, a wrapper for an un-ordered map type
type Iterator ¶
Iterator is a more narrow subset of mgo's Iter type that provides the opportunity to mock results, and avoids a strict dependency between mgo and migrations definitions.
func NewCombinedIterator ¶
NewCombinedIterator produces a DocumentIterator that is an mgo.Iter, with a modified Close() method that also closes the provided mgo session after closing the iterator.
type Results ¶
Results reflect the output of a database operation and is part of the query interface, and is returned by the pipeline (e.g aggregation operation.)