Documentation ¶
Overview ¶
Wraps MongoDB to make it compatible with the model package.
Built on top of Gustavo Niemeyer's great mgo package: http://labix.org/mgo
Index ¶
- Variables
- func DereferenceIterator(refs ...Ref) model.Iterator
- func FailsafeDereferenceIterator(refs ...Ref) (i model.Iterator, errors []error)
- func FindRefWithID(refs []Ref, id bson.ObjectId) (index int, found bool)
- func InitLocalhost(database, user, password string) (err error)
- func InitRefs(document interface{})
- func MatchBsonField(bsonName string) reflection.MatchStructFieldFunc
- func ReverseBsonD(d bson.D)
- func SortRefs(refs []Ref, lessFunc func(a, b *Ref) bool)
- func ValidateRefs(refs []Ref) (validRefs []Ref, invalidRefs []Ref)
- type Collection
- func (self *Collection) Collection() *Collection
- func (self *Collection) Count() (n int, err error)
- func (self *Collection) DocumentWithID(id bson.ObjectId, subDocSelectors ...string) (document interface{}, err error)
- func (self *Collection) DocumentWithIDIterator(id bson.ObjectId, subDocSelectors ...string) model.Iterator
- func (self *Collection) Explain() string
- func (self *Collection) Filter(selector string, value interface{}) Query
- func (self *Collection) FilterAllIn(selector string, values ...interface{}) Query
- func (self *Collection) FilterArraySize(selector string, size int) Query
- func (self *Collection) FilterContains(selector string, str string) Query
- func (self *Collection) FilterContainsCaseInsensitive(selector string, str string) Query
- func (self *Collection) FilterEndsWith(selector string, str string) Query
- func (self *Collection) FilterEndsWithCaseInsensitive(selector string, str string) Query
- func (self *Collection) FilterEqualCaseInsensitive(selector string, str string) Query
- func (self *Collection) FilterExists(selector string, exists bool) Query
- func (self *Collection) FilterFunc(passFilter model.FilterFunc) model.Iterator
- func (self *Collection) FilterGreater(selector string, value interface{}) Query
- func (self *Collection) FilterGreaterEqual(selector string, value interface{}) Query
- func (self *Collection) FilterIn(selector string, values ...interface{}) Query
- func (self *Collection) FilterLess(selector string, value interface{}) Query
- func (self *Collection) FilterLessEqual(selector string, value interface{}) Query
- func (self *Collection) FilterModulo(selector string, divisor, result interface{}) Query
- func (self *Collection) FilterNotEqual(selector string, value interface{}) Query
- func (self *Collection) FilterNotIn(selector string, values ...interface{}) Query
- func (self *Collection) FilterRef(selector string, ref ...Ref) Query
- func (self *Collection) FilterReferenced(refs []Ref) Query
- func (self *Collection) FilterStartsWith(selector string, str string) Query
- func (self *Collection) FilterStartsWithCaseInsensitive(selector string, str string) Query
- func (self *Collection) FilterWhere(javascript string) Query
- func (self *Collection) GetOrCreateOne() (document interface{}, found bool, err error)
- func (self *Collection) IDs() (ids []bson.ObjectId, err error)
- func (self *Collection) Init()
- func (self *Collection) InitDocument(doc interface{}, subDocSelectors ...string)
- func (self *Collection) Insert(document interface{}) (id bson.ObjectId, err error)
- func (self *Collection) IsFilter() bool
- func (self *Collection) Iterator() model.Iterator
- func (self *Collection) Limit(limit int) Query
- func (self *Collection) NewDocument(subDocSelectors ...string) interface{}
- func (self *Collection) One() (document interface{}, err error)
- func (self *Collection) OneID() (id bson.ObjectId, err error)
- func (self *Collection) Or() Query
- func (self *Collection) ParentQuery() Query
- func (self *Collection) Ref(id bson.ObjectId) Ref
- func (self *Collection) Refs() (refs []Ref, err error)
- func (self *Collection) Remove(ids ...bson.ObjectId) error
- func (self *Collection) RemoveAll() error
- func (self *Collection) RemoveAllNotIn(ids ...bson.ObjectId) error
- func (self *Collection) Selector() string
- func (self *Collection) Skip(skip int) Query
- func (self *Collection) Sort(selector string) Query
- func (self *Collection) SortFunc(lessFunc func(a, b interface{}) bool) model.Iterator
- func (self *Collection) SortReverse(selector string) Query
- func (self *Collection) SubDocument(selector string) Query
- func (self *Collection) TryDocumentWithID(id bson.ObjectId, subDocSelectors ...string) (document interface{}, found bool, err error)
- func (self *Collection) TryDocumentWithIDIterator(id bson.ObjectId, subDocSelectors ...string) model.Iterator
- func (self *Collection) TryOne() (document interface{}, found bool, err error)
- func (self *Collection) TryOneID() (id bson.ObjectId, found bool, err error)
- func (self *Collection) Update(id bson.ObjectId, document interface{}) (err error)
- func (self *Collection) ValidateSelector(subDocSelectors ...string) (err error)
- type Configuration
- type Document
- type DocumentBase
- func (self *DocumentBase) Collection() *Collection
- func (self *DocumentBase) Init(collection *Collection, embeddingStruct interface{})
- func (self *DocumentBase) Iterator() model.Iterator
- func (self *DocumentBase) ObjectId() bson.ObjectId
- func (self *DocumentBase) Ref() Ref
- func (self *DocumentBase) Remove() error
- func (self *DocumentBase) Save() error
- func (self *DocumentBase) SetObjectId(id bson.ObjectId)
- type ForeignRef
- type MongoIterator
- type Query
- type QueryError
- func (self *QueryError) Collection() *Collection
- func (self *QueryError) Count() (n int, err error)
- func (self *QueryError) Explain() string
- func (self *QueryError) Filter(selector string, value interface{}) Query
- func (self *QueryError) FilterAllIn(selector string, values ...interface{}) Query
- func (self *QueryError) FilterArraySize(selector string, size int) Query
- func (self *QueryError) FilterContains(selector string, str string) Query
- func (self *QueryError) FilterContainsCaseInsensitive(selector string, str string) Query
- func (self *QueryError) FilterEndsWith(selector string, str string) Query
- func (self *QueryError) FilterEndsWithCaseInsensitive(selector string, str string) Query
- func (self *QueryError) FilterEqualCaseInsensitive(selector string, str string) Query
- func (self *QueryError) FilterExists(selector string, exists bool) Query
- func (self *QueryError) FilterFunc(passFilter model.FilterFunc) model.Iterator
- func (self *QueryError) FilterGreater(selector string, value interface{}) Query
- func (self *QueryError) FilterGreaterEqual(selector string, value interface{}) Query
- func (self *QueryError) FilterIn(selector string, values ...interface{}) Query
- func (self *QueryError) FilterLess(selector string, value interface{}) Query
- func (self *QueryError) FilterLessEqual(selector string, value interface{}) Query
- func (self *QueryError) FilterModulo(selector string, divisor, result interface{}) Query
- func (self *QueryError) FilterNotEqual(selector string, value interface{}) Query
- func (self *QueryError) FilterNotIn(selector string, values ...interface{}) Query
- func (self *QueryError) FilterRef(selector string, ref ...Ref) Query
- func (self *QueryError) FilterStartsWith(selector string, str string) Query
- func (self *QueryError) FilterStartsWithCaseInsensitive(selector string, str string) Query
- func (self *QueryError) FilterWhere(javascript string) Query
- func (self *QueryError) GetOrCreateOne() (document interface{}, found bool, err error)
- func (self *QueryError) IDs() (ids []bson.ObjectId, err error)
- func (self *QueryError) IsFilter() bool
- func (self *QueryError) Iterator() model.Iterator
- func (self *QueryError) Limit(int) Query
- func (self *QueryError) One() (document interface{}, err error)
- func (self *QueryError) OneID() (id bson.ObjectId, err error)
- func (self *QueryError) Or() Query
- func (self *QueryError) ParentQuery() Query
- func (self *QueryError) Refs() (refs []Ref, err error)
- func (self *QueryError) RemoveAll() error
- func (self *QueryError) Selector() string
- func (self *QueryError) Skip(int) Query
- func (self *QueryError) Sort(selector string) Query
- func (self *QueryError) SortFunc(less func(a, b interface{}) bool) model.Iterator
- func (self *QueryError) SortReverse(selector string) Query
- func (self *QueryError) SubDocument(selector string) Query
- func (self *QueryError) TryOne() (document interface{}, found bool, err error)
- func (self *QueryError) TryOneID() (id bson.ObjectId, found bool, err error)
- type Ref
- func (self *Ref) Collection() (collection *Collection, err error)
- func (self *Ref) Get() (doc interface{}, err error)
- func (self Ref) GetBSON() (interface{}, error)
- func (self *Ref) IsEmpty() bool
- func (self *Ref) Reference()
- func (self *Ref) References(doc Document) (ok bool, err error)
- func (self *Ref) Required(metaData *model.MetaData) bool
- func (self *Ref) Set(document Document)
- func (self *Ref) SetBSON(raw bson.Raw) error
- func (self *Ref) SetEmpty()
- func (self *Ref) SetString(str string) error
- func (self *Ref) String() string
- func (self *Ref) TryGet() (doc interface{}, ok bool, err error)
- func (self *Ref) Validate(metaData *model.MetaData) error
- type SortableRefs
- type SubDocument
- type SubDocumentBase
- func (self *SubDocumentBase) Collection() *Collection
- func (self *SubDocumentBase) Init(collection *Collection, selector string, embeddingStruct interface{})
- func (self *SubDocumentBase) Iterator() model.Iterator
- func (self *SubDocumentBase) RemoveRootDocument() error
- func (self *SubDocumentBase) RootDocumentObjectId() bson.ObjectId
- func (self *SubDocumentBase) RootDocumentSetObjectId(id bson.ObjectId)
- func (self *SubDocumentBase) Save() error
Constants ¶
This section is empty.
Variables ¶
var Config = Configuration{ Safe: mgo.Safe{FSync: true, J: true}, CheckQuerySelectors: true, }
var Database *mgo.Database
Functions ¶
func DereferenceIterator ¶
Returns an iterator of dereferenced refs, or an error iterator if there was an error
func FailsafeDereferenceIterator ¶
Returns an iterator for all refs without error and a slice of the errors
func InitLocalhost ¶
func MatchBsonField ¶
func MatchBsonField(bsonName string) reflection.MatchStructFieldFunc
func ReverseBsonD ¶
func ValidateRefs ¶
Types ¶
type Collection ¶
type Collection struct { Name string DocumentType reflect.Type // contains filtered or unexported fields }
Collection represents a MongoDB collection and implements mongo.Query for all documents in the collection.
Example for creating, modifying and saving a document:
user := models.Users.NewDocument().(*models.User) user.Name.First.Set("Erik") user.Name.Last.Set("Unger") err := user.Save()
func CollectionByName ¶
func CollectionByName(name string) (collection *Collection, ok bool)
func NewCollection ¶
func NewCollection(name string, documentPrototype interface{}) *Collection
func (*Collection) Collection ¶
func (self *Collection) Collection() *Collection
func (*Collection) Count ¶
func (self *Collection) Count() (n int, err error)
func (*Collection) DocumentWithID ¶
func (self *Collection) DocumentWithID(id bson.ObjectId, subDocSelectors ...string) (document interface{}, err error)
func (*Collection) DocumentWithIDIterator ¶
func (*Collection) FilterAllIn ¶
func (*Collection) FilterArraySize ¶
func (*Collection) FilterContains ¶
func (*Collection) FilterContainsCaseInsensitive ¶
func (*Collection) FilterEndsWith ¶
func (*Collection) FilterEndsWithCaseInsensitive ¶
func (*Collection) FilterEqualCaseInsensitive ¶
func (*Collection) FilterExists ¶
func (*Collection) FilterFunc ¶
func (self *Collection) FilterFunc(passFilter model.FilterFunc) model.Iterator
func (*Collection) FilterGreater ¶
func (*Collection) FilterGreaterEqual ¶
func (*Collection) FilterLess ¶
func (*Collection) FilterLessEqual ¶
func (*Collection) FilterModulo ¶
func (*Collection) FilterNotEqual ¶
func (*Collection) FilterNotIn ¶
func (*Collection) FilterReferenced ¶
func (self *Collection) FilterReferenced(refs []Ref) Query
func (*Collection) FilterStartsWith ¶
func (*Collection) FilterStartsWithCaseInsensitive ¶
func (*Collection) FilterWhere ¶
func (*Collection) GetOrCreateOne ¶
func (*Collection) Init ¶
func (self *Collection) Init()
func (*Collection) InitDocument ¶
func (self *Collection) InitDocument(doc interface{}, subDocSelectors ...string)
func (*Collection) Insert ¶
func (self *Collection) Insert(document interface{}) (id bson.ObjectId, err error)
Inserts document regardless if it's already in the collection If document has a DocumentBase, the ID will be updated to the newly created one
func (*Collection) NewDocument ¶
func (self *Collection) NewDocument(subDocSelectors ...string) interface{}
return error?
func (*Collection) ParentQuery ¶
func (self *Collection) ParentQuery() Query
func (*Collection) RemoveAllNotIn ¶
func (self *Collection) RemoveAllNotIn(ids ...bson.ObjectId) error
func (*Collection) Selector ¶
func (self *Collection) Selector() string
func (*Collection) SortReverse ¶
func (*Collection) SubDocument ¶
func (*Collection) TryDocumentWithID ¶
func (*Collection) TryDocumentWithIDIterator ¶
func (*Collection) Update ¶
func (self *Collection) Update(id bson.ObjectId, document interface{}) (err error)
func (*Collection) ValidateSelector ¶
func (self *Collection) ValidateSelector(subDocSelectors ...string) (err error)
type Configuration ¶
type Configuration struct { Host string Database string User string Password string Safe mgo.Safe CheckQuerySelectors bool }
func (*Configuration) Close ¶
func (self *Configuration) Close() error
func (*Configuration) Init ¶
func (self *Configuration) Init() error
func (*Configuration) Name ¶
func (self *Configuration) Name() string
type DocumentBase ¶
type DocumentBase struct { ID bson.ObjectId `bson:"_id,omitempty" gostart:"-"` // contains filtered or unexported fields }
func (*DocumentBase) Collection ¶
func (self *DocumentBase) Collection() *Collection
func (*DocumentBase) Init ¶
func (self *DocumentBase) Init(collection *Collection, embeddingStruct interface{})
func (*DocumentBase) Iterator ¶
func (self *DocumentBase) Iterator() model.Iterator
func (*DocumentBase) ObjectId ¶
func (self *DocumentBase) ObjectId() bson.ObjectId
func (*DocumentBase) Ref ¶
func (self *DocumentBase) Ref() Ref
func (*DocumentBase) Remove ¶
func (self *DocumentBase) Remove() error
func (*DocumentBase) Save ¶
func (self *DocumentBase) Save() error
func (*DocumentBase) SetObjectId ¶
func (self *DocumentBase) SetObjectId(id bson.ObjectId)
type ForeignRef ¶
type ForeignRef struct { Collection *Collection Selector string }
type MongoIterator ¶
type MongoIterator struct {
// contains filtered or unexported fields
}
func (*MongoIterator) Err ¶
func (self *MongoIterator) Err() error
func (*MongoIterator) Next ¶
func (self *MongoIterator) Next() interface{}
type Query ¶
type Query interface { Selector() string ParentQuery() Query Collection() *Collection SubDocument(selector string) Query Skip(int) Query Limit(int) Query Sort(selector string) Query // Chain Sort() and SortReverse() for multi value sorting SortReverse(selector string) Query // Chain Sort() and SortReverse() for multi value sorting SortFunc(less func(a, b interface{}) bool) model.Iterator // Last query of chain // FilterX must be the first query on a Collection IsFilter() bool Filter(selector string, value interface{}) Query FilterWhere(javascript string) Query // Filter via a Go function. Note that all documents have to be loaded // in memory in order for Go code to be able to filter it. FilterFunc(passFilter model.FilterFunc) model.Iterator FilterRef(selector string, ref ...Ref) Query FilterEqualCaseInsensitive(selector string, str string) Query FilterNotEqual(selector string, value interface{}) Query FilterLess(selector string, value interface{}) Query FilterGreater(selector string, value interface{}) Query FilterLessEqual(selector string, value interface{}) Query FilterGreaterEqual(selector string, value interface{}) Query FilterModulo(selector string, divisor, result interface{}) Query FilterIn(selector string, values ...interface{}) Query FilterNotIn(selector string, values ...interface{}) Query FilterAllIn(selector string, values ...interface{}) Query FilterArraySize(selector string, size int) Query FilterStartsWith(selector string, str string) Query FilterStartsWithCaseInsensitive(selector string, str string) Query FilterEndsWith(selector string, str string) Query FilterEndsWithCaseInsensitive(selector string, str string) Query FilterContains(selector string, str string) Query FilterContainsCaseInsensitive(selector string, str string) Query FilterExists(selector string, exists bool) Query Or() Query // Statistics Count() (n int, err error) // Distinct() int Explain() string // Read One() (document interface{}, err error) TryOne() (document interface{}, found bool, err error) GetOrCreateOne() (document interface{}, found bool, err error) Iterator() model.Iterator OneID() (id bson.ObjectId, err error) TryOneID() (id bson.ObjectId, found bool, err error) IDs() (ids []bson.ObjectId, err error) Refs() (refs []Ref, err error) // RemoveAll ignores Skip() and Limit() RemoveAll() error // contains filtered or unexported methods }
Query is the interface with all query methods for mongo.
type QueryError ¶
type QueryError struct { Err error // contains filtered or unexported fields }
QueryError implements Query, but all it does is hold and return an error generated by another query.
func (*QueryError) Collection ¶
func (self *QueryError) Collection() *Collection
func (*QueryError) Count ¶
func (self *QueryError) Count() (n int, err error)
func (*QueryError) Explain ¶
func (self *QueryError) Explain() string
func (*QueryError) Filter ¶
func (self *QueryError) Filter(selector string, value interface{}) Query
func (*QueryError) FilterAllIn ¶
func (self *QueryError) FilterAllIn(selector string, values ...interface{}) Query
func (*QueryError) FilterArraySize ¶
func (self *QueryError) FilterArraySize(selector string, size int) Query
func (*QueryError) FilterContains ¶
func (self *QueryError) FilterContains(selector string, str string) Query
func (*QueryError) FilterContainsCaseInsensitive ¶
func (self *QueryError) FilterContainsCaseInsensitive(selector string, str string) Query
func (*QueryError) FilterEndsWith ¶
func (self *QueryError) FilterEndsWith(selector string, str string) Query
func (*QueryError) FilterEndsWithCaseInsensitive ¶
func (self *QueryError) FilterEndsWithCaseInsensitive(selector string, str string) Query
func (*QueryError) FilterEqualCaseInsensitive ¶
func (self *QueryError) FilterEqualCaseInsensitive(selector string, str string) Query
func (*QueryError) FilterExists ¶
func (self *QueryError) FilterExists(selector string, exists bool) Query
func (*QueryError) FilterFunc ¶
func (self *QueryError) FilterFunc(passFilter model.FilterFunc) model.Iterator
func (*QueryError) FilterGreater ¶
func (self *QueryError) FilterGreater(selector string, value interface{}) Query
func (*QueryError) FilterGreaterEqual ¶
func (self *QueryError) FilterGreaterEqual(selector string, value interface{}) Query
func (*QueryError) FilterIn ¶
func (self *QueryError) FilterIn(selector string, values ...interface{}) Query
func (*QueryError) FilterLess ¶
func (self *QueryError) FilterLess(selector string, value interface{}) Query
func (*QueryError) FilterLessEqual ¶
func (self *QueryError) FilterLessEqual(selector string, value interface{}) Query
func (*QueryError) FilterModulo ¶
func (self *QueryError) FilterModulo(selector string, divisor, result interface{}) Query
func (*QueryError) FilterNotEqual ¶
func (self *QueryError) FilterNotEqual(selector string, value interface{}) Query
func (*QueryError) FilterNotIn ¶
func (self *QueryError) FilterNotIn(selector string, values ...interface{}) Query
func (*QueryError) FilterStartsWith ¶
func (self *QueryError) FilterStartsWith(selector string, str string) Query
func (*QueryError) FilterStartsWithCaseInsensitive ¶
func (self *QueryError) FilterStartsWithCaseInsensitive(selector string, str string) Query
func (*QueryError) FilterWhere ¶
func (self *QueryError) FilterWhere(javascript string) Query
func (*QueryError) GetOrCreateOne ¶
func (self *QueryError) GetOrCreateOne() (document interface{}, found bool, err error)
func (*QueryError) IsFilter ¶
func (self *QueryError) IsFilter() bool
func (*QueryError) Iterator ¶
func (self *QueryError) Iterator() model.Iterator
func (*QueryError) Limit ¶
func (self *QueryError) Limit(int) Query
func (*QueryError) One ¶
func (self *QueryError) One() (document interface{}, err error)
func (*QueryError) Or ¶
func (self *QueryError) Or() Query
func (*QueryError) ParentQuery ¶
func (self *QueryError) ParentQuery() Query
func (*QueryError) Refs ¶
func (self *QueryError) Refs() (refs []Ref, err error)
func (*QueryError) RemoveAll ¶
func (self *QueryError) RemoveAll() error
func (*QueryError) Selector ¶
func (self *QueryError) Selector() string
func (*QueryError) Skip ¶
func (self *QueryError) Skip(int) Query
func (*QueryError) Sort ¶
func (self *QueryError) Sort(selector string) Query
func (*QueryError) SortFunc ¶
func (self *QueryError) SortFunc(less func(a, b interface{}) bool) model.Iterator
func (*QueryError) SortReverse ¶
func (self *QueryError) SortReverse(selector string) Query
func (*QueryError) SubDocument ¶
func (self *QueryError) SubDocument(selector string) Query
func (*QueryError) TryOne ¶
func (self *QueryError) TryOne() (document interface{}, found bool, err error)
type Ref ¶
Ref holds a mongo.ID and the name of the collection of the referenced document. Only the ID will be saved in MongoDB, the collection name is for validation and convenience functions only.
func (*Ref) Collection ¶
func (self *Ref) Collection() (collection *Collection, err error)
type SortableRefs ¶
func (*SortableRefs) Len ¶
func (self *SortableRefs) Len() int
func (*SortableRefs) Less ¶
func (self *SortableRefs) Less(i, j int) bool
func (*SortableRefs) Swap ¶
func (self *SortableRefs) Swap(i, j int)
type SubDocument ¶
type SubDocumentBase ¶
type SubDocumentBase struct {
// contains filtered or unexported fields
}
func (*SubDocumentBase) Collection ¶
func (self *SubDocumentBase) Collection() *Collection
func (*SubDocumentBase) Init ¶
func (self *SubDocumentBase) Init(collection *Collection, selector string, embeddingStruct interface{})
func (*SubDocumentBase) Iterator ¶
func (self *SubDocumentBase) Iterator() model.Iterator
func (*SubDocumentBase) RemoveRootDocument ¶
func (self *SubDocumentBase) RemoveRootDocument() error
func (*SubDocumentBase) RootDocumentObjectId ¶
func (self *SubDocumentBase) RootDocumentObjectId() bson.ObjectId
Implements DocumentInterface
func (*SubDocumentBase) RootDocumentSetObjectId ¶
func (self *SubDocumentBase) RootDocumentSetObjectId(id bson.ObjectId)
func (*SubDocumentBase) Save ¶
func (self *SubDocumentBase) Save() error
Source Files ¶
- collection.go
- config.go
- doc.go
- document.go
- documentbase.go
- filterallinquery.go
- filterarraysizequery.go
- filtercontainsquery.go
- filterendswithquery.go.go
- filterequalcaseinsensitivequery.go
- filterexistsquery.go
- filtergreaterequalquery.go
- filtergreaterquery.go
- filterinquery.go
- filterlessequalquery.go
- filterlessquery.go
- filtermoduloquery.go
- filternotequalquery.go
- filternotinquery.go
- filterquery.go
- filterquerybase.go
- filterrefquery.go
- filterstartswithquery.go
- functions.go
- limitquery.go
- mongoiterator.go
- orquery.go
- query.go
- querybase.go
- queryerror.go
- ref.go
- skipquery.go
- sortquery.go
- subdocument.go
- subdocumentbase.go
- subdocumentquery.go