Documentation ¶
Overview ¶
Package nosql implements wrappers for go.mongodb.org/mongo-driver
Index ¶
- type Aggregater
- 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 Finder
- type IniFile
- type ManyResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Aggregater ¶ added in v1.2.1
type Aggregater interface {
Aggregate(ctx context.Context, pipeline interface{}, opts ...*options.AggregateOptions) (*mongo.Cursor, error)
}
Aggregater is a part of the mongo.Collection interface.
type Collection ¶
type Collection struct {
*mongo.Collection
}
Collection is a mongo.Collection wrapper.
func (*Collection) AggregateMany ¶ added in v1.2.0
func (c *Collection) AggregateMany( ctx context.Context, pipeline interface{}, opts ...*options.AggregateOptions, ) *ManyResult
AggregateMany returns aggregate command results.
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 Finder ¶ added in v1.1.0
type Finder interface {
Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (*mongo.Cursor, error)
}
Finder is a part of the mongo.Collection interface.
type ManyResult ¶
type ManyResult struct {
// contains filtered or unexported fields
}
ManyResult contains Find results.
func AggregateMany ¶ added in v1.2.1
func AggregateMany( ctx context.Context, aggregater Aggregater, pipeline interface{}, opts ...*options.AggregateOptions, ) *ManyResult
AggregateMany executes an aggregate command against the collection. Any reference to mongo.Collection conforms to Aggregater interface.
func FindMany ¶ added in v1.1.0
func FindMany( ctx context.Context, finder Finder, filter interface{}, opts ...*options.FindOptions, ) *ManyResult
FindMany finds all documents from the collection that match the filter and options. Any reference to mongo.Collection conforms to Finder interface.
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.