Documentation
¶
Overview ¶
Package mgo provides MongoDB database connection and operation wrapper.
Index ¶
- Constants
- func Call(fn func(pool.Src) error) result.VoidResult
- func Close()
- func CollectionNames(dbname string) result.Result[[]string]
- func DatabaseNames() result.Result[[]string]
- func Error() error
- func Len() int
- func Mgo(resultPtr interface{}, operate string, option map[string]interface{}) result.Result[any]
- func Refresh()
- type Count
- type Find
- type Insert
- type List
- type MgoSrc
- type Operator
- type Remove
- type Update
- type UpdateAll
- type Upsert
Constants ¶
const (
MaxLen int = 5000 // batch size for bulk insert
)
Variables ¶
This section is empty.
Functions ¶
func Call ¶
func Call(fn func(pool.Src) error) result.VoidResult
Call executes fn with a pooled MongoDB connection.
func CollectionNames ¶
CollectionNames returns collection names for the given database.
func DatabaseNames ¶
DatabaseNames returns all database names.
Types ¶
type Count ¶
type Count struct {
Database string // database name
Collection string // collection name
Query map[string]interface{} // query filter
}
Count returns the number of documents matching the query.
type Find ¶
type Find struct {
Database string // database name
Collection string // collection name
Query map[string]interface{} // query filter
Sort []string // sort fields, e.g. Sort("firstname", "-lastname") for asc firstname, desc lastname
Skip int // skip first n documents
Limit int // return at most n documents
Select interface{} // projection, e.g. {"name":1} to return only name
}
Find performs a conditional query on the specified collection.
type Insert ¶
type Insert struct {
Database string // database name
Collection string // collection name
Docs []map[string]interface{} // documents to insert
}
Insert inserts new documents into the collection.
type List ¶
type List struct {
Dbs []string // list of database names to query (empty = all)
}
List returns a map of database names to their collection names.
type MgoSrc ¶
MgoSrc wraps MongoDB session for connection pool.
func (*MgoSrc) Close ¶
func (ms *MgoSrc) Close()
Close closes the session when removed from the pool.
type Remove ¶
type Remove struct {
Database string // database name
Collection string // collection name
Selector map[string]interface{} // document selector
}
Remove deletes documents matching the selector.
type Update ¶
type Update struct {
Database string // database name
Collection string // collection name
Selector map[string]interface{} // document selector
Change map[string]interface{} // update document
}
Update updates the first document matching the selector.
type UpdateAll ¶
type UpdateAll struct {
Database string // database name
Collection string // collection name
Selector map[string]interface{} // document selector
Change map[string]interface{} // update document
}
UpdateAll updates all documents matching the selector.