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 ¶
- Variables
- func ResolveCursorOne(ctx context.Context, iter *mongo.Cursor, result interface{}) error
- func ResultsNotFound(err error) bool
- type Aggregation
- type Bulk
- type BulkResult
- type Change
- type ChangeInfo
- type Collection
- type CombinedCloser
- type Database
- type Document
- type Iterator
- type MigrationOperation
- type Processor
- type Query
- type Results
- type Session
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("document not found")
Functions ¶
func ResolveCursorOne ¶
ResolveCursorOne decodes the first result in a cursor, for use in "FindOne" cases.
func ResultsNotFound ¶
Types ¶
type Aggregation ¶
type Aggregation interface { Hint(interface{}) Aggregation Results }
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{}) Aggregation 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
}
func (CombinedCloser) Close ¶
func (c CombinedCloser) Close() error
type Database ¶
type Database interface { Name() string C(string) Collection CreateCollection(coll string) (Collection, error) 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 MigrationOperation ¶
MigrationOperation defines the function object that performs the transformation in the manual migration migrations. Register these functions using RegisterMigrationOperation.
Implementors of MigrationOperations are responsible for implementing idempotent operations.
type Processor ¶
type Processor interface { Load(Session, model.Namespace, map[string]interface{}) Iterator Migrate(Iterator) error }
Processor defines the process for processing a stream of documents using an Iterator, which resembles mgo's Iter operation.
type Query ¶
type Query interface { Count() (int, error) Limit(int) Query Select(interface{}) Query Skip(n int) Query Sort(...string) Query // Hint tells the query which index to use. The input must be either the // name of the index as a string or the index specification as a document. Hint(interface{}) Query Apply(Change, interface{}) (*ChangeInfo, error) Results }
type Results ¶
Results reflect the output of a database operation and is part of the query interface