Documentation
¶
Overview ¶
Package nosql implements wrappers for go.mongodb.org/mongo-driver
Index ¶
- type Collection
- type Database
- func (db *Database) Collection(name string, opts ...*options.CollectionOptions) *Collection
- func (db *Database) InitSequence(ctx context.Context, idName string, idValue int64) error
- func (db *Database) NextSequence(ctx context.Context, idName string) (int64, error)
- func (db *Database) NextSequences(ctx context.Context, idName string, size int64) (int64, error)
- type Databases
- type IniFile
- type ManyResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type Collection struct {
*mongo.Collection
}
Collection is a mongo.Collection wrapper
func (*Collection) FindMany ¶
func (c *Collection) FindMany( ctx context.Context, filter interface{}, opts ...*options.FindOptions, ) *ManyResult
FindMany finds all documents that match the filter and options
type Database ¶
Database is a mongo.Database wrapper
func NewDatabase ¶
NewDatabase creates a new Database instance
func (*Database) Collection ¶
func (db *Database) Collection(name string, opts ...*options.CollectionOptions) *Collection
Collection returns a handle for collection of database
func (*Database) InitSequence ¶
InitSequence sets last used value for ID name; InitSequence needs for data migration only
func (*Database) NextSequence ¶
NextSequence returns next ID value. Make sure that the "counters" collection has an index by "id" field
type Databases ¶
type Databases struct {
// contains filtered or unexported fields
}
Databases represents mongodb database pool
func Open ¶
func Open(ini IniFile, opts ...*options.ClientOptions) *Databases
Open returns mongodb database pool
type ManyResult ¶
type ManyResult struct {
// contains filtered or unexported fields
}
ManyResult contains Find results
func (*ManyResult) Cursor ¶
func (a *ManyResult) Cursor() *mongo.Cursor
Cursor returns a underlying *mongo.Cursor
func (*ManyResult) Decode ¶
func (a *ManyResult) Decode(data interface{}) error
Decode decodes all found documents into a variable. The data parameter may be a pointer to an slice of struct. Also data parameter may be a pointer to an slice of pointers to a struct. For examples:
var data1 []Struct // slice of struct
err := collection.FindMany(ctx, bson.D{}).Decode(&data1) // pointer to an slice of ...
var data2 []*Struct // slice of pointers to a struct
err := collection.FindMany(ctx, bson.D{}).Decode(&data2) // pointer to an slice of ...
If no documents are found, an empty slice is returned.