Documentation ¶
Index ¶
- Variables
- func CreateSession(client *mongo.Client) (mongo.Session, error)
- func CreateTransaction(client *mongo.Client, queries func(sc mongo.SessionContext) error) error
- func CreateTransactionOptions() *options.TransactionOptions
- func GetObjectIdFromString(id string) (*primitive.ObjectID, error)
- func PrepareFindOneOptions(projection interface{}, sort interface{}) *options.FindOneOptions
- func PrepareFindOptions(projection interface{}, sort interface{}, limit int64, skip int64) *options.FindOptions
- func PrepareUpdateOptions(upsert bool) *options.UpdateOptions
- type Collection
- type CompoundFieldIndex
- type Config
- type ConnectionHandler
- type DefaultConnectionHandler
- type FieldIndex
- type Order
- type SingleFieldIndex
Constants ¶
This section is empty.
Variables ¶
var ( FailedToCreateDocumentError = errors.New("failed to create document") FailedToStartSessionError = errors.New("failed to start session") FailedToCreateSingleFieldIndexError = errors.New("failed to create single field index") FailedToCreateCompoundIndexError = errors.New("failed to create compound index") )
Functions ¶
func CreateSession ¶ added in v0.6.17
CreateSession creates a new session
func CreateTransaction ¶ added in v0.6.17
CreateTransaction creates a new transaction
func CreateTransactionOptions ¶ added in v0.6.17
func CreateTransactionOptions() *options.TransactionOptions
CreateTransactionOptions creates the transaction options
func GetObjectIdFromString ¶ added in v0.6.12
GetObjectIdFromString gets the object ID from the string
func PrepareFindOneOptions ¶ added in v0.6.16
func PrepareFindOneOptions(projection interface{}, sort interface{}) *options.FindOneOptions
PrepareFindOneOptions prepares the find one options
func PrepareFindOptions ¶ added in v0.6.25
func PrepareFindOptions(projection interface{}, sort interface{}, limit int64, skip int64) *options.FindOptions
PrepareFindOptions prepares the find options
func PrepareUpdateOptions ¶ added in v0.6.25
func PrepareUpdateOptions(upsert bool) *options.UpdateOptions
PrepareUpdateOptions prepares the update options
Types ¶
type Collection ¶
type Collection struct { Name string SingleFieldIndexes *[]*SingleFieldIndex CompoundIndexes *[]*CompoundFieldIndex }
Collection represents a MongoDB collection
func NewCollection ¶
func NewCollection( name string, singleFieldIndexes *[]*SingleFieldIndex, compoundIndexes *[]*CompoundFieldIndex, ) *Collection
NewCollection creates a new MongoDB collection
func (*Collection) CreateCollection ¶
func (c *Collection) CreateCollection(database *mongo.Database) ( collection *mongo.Collection, err error, )
CreateCollection creates the collection
type CompoundFieldIndex ¶
type CompoundFieldIndex struct {
Model *mongo.IndexModel
}
CompoundFieldIndex represents a compound field index
func NewCompoundFieldIndex ¶
func NewCompoundFieldIndex( fieldIndexes []*FieldIndex, unique bool, ) *CompoundFieldIndex
NewCompoundFieldIndex creates a new compound field index
type ConnectionHandler ¶
type ConnectionHandler interface { Connect() (*mongo.Client, error) GetClient() (*mongo.Client, error) Disconnect() }
ConnectionHandler interface
type DefaultConnectionHandler ¶
type DefaultConnectionHandler struct { Ctx context.Context Cancel context.CancelFunc ClientOptions *options.ClientOptions Client *mongo.Client }
DefaultConnectionHandler struct
func NewDefaultConnectionHandler ¶
func NewDefaultConnectionHandler(config *Config) DefaultConnectionHandler
NewDefaultConnectionHandler creates a new connection
func (DefaultConnectionHandler) Connect ¶
func (d DefaultConnectionHandler) Connect() (*mongo.Client, error)
Connect returns a new MongoDB client
func (DefaultConnectionHandler) Disconnect ¶
func (d DefaultConnectionHandler) Disconnect()
Disconnect closes the MongoDB client connection
type FieldIndex ¶
func NewFieldIndex ¶
func NewFieldIndex(name string, order Order) *FieldIndex
NewFieldIndex creates a new field index
type SingleFieldIndex ¶
type SingleFieldIndex struct {
Model *mongo.IndexModel
}
func NewSingleFieldIndex ¶
func NewSingleFieldIndex(fieldIndex FieldIndex, unique bool) *SingleFieldIndex
NewSingleFieldIndex creates a new single field index