Documentation
¶
Index ¶
- Variables
- type Auth
- type Base
- func (model *Base) Aggregate(ctx context.Context, pipeline, results interface{}, ...) error
- func (model *Base) BulkWrite(ctx context.Context, models []mongo.WriteModel, ...) (*mongo.BulkWriteResult, error)
- func (model *Base) Client() Client
- func (model *Base) Clone(opts ...*options.CollectionOptions) (*mongo.Collection, error)
- func (model *Base) Collection() string
- func (model *Base) Count(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error)
- func (model *Base) CountDocuments(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error)
- func (model *Base) Database() string
- func (model *Base) DeleteId(ctx context.Context, id string, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
- func (model *Base) DeleteMany(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
- func (model *Base) DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
- func (model *Base) Distinct(ctx context.Context, fieldName string, filter interface{}, ...) ([]interface{}, error)
- func (model *Base) Do(ctx context.Context, exec Exec) (interface{}, error)
- func (model *Base) DoWithSession(ctx context.Context, exec SessionExec) error
- func (model *Base) DoWithTransaction(ctx context.Context, exec ModelExec) (interface{}, error)
- func (model *Base) Drop(ctx context.Context) error
- func (model *Base) EstimatedDocumentCount(ctx context.Context, opts ...*options.EstimatedDocumentCountOptions) (int64, error)
- func (model *Base) Find(ctx context.Context, filter interface{}, results interface{}, ...) error
- func (model *Base) FindId(ctx context.Context, id string, result interface{}, ...) error
- func (model *Base) FindOne(ctx context.Context, filter interface{}, result interface{}, ...) error
- func (model *Base) FindOneAndDelete(ctx context.Context, filter interface{}, result interface{}, ...) error
- func (model *Base) FindOneAndReplace(ctx context.Context, filter, replacement, result interface{}, ...) error
- func (model *Base) FindOneAndUpdate(ctx context.Context, filter, update, result interface{}, ...) error
- func (model *Base) FindOneAndUpsert(ctx context.Context, filter, update, result interface{}, ...) error
- func (model *Base) Indexes() mongo.IndexView
- func (model *Base) InsertMany(ctx context.Context, documents []interface{}, ...) (*mongo.InsertManyResult, error)
- func (model *Base) InsertOne(ctx context.Context, document interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)
- func (model *Base) ReplaceOne(ctx context.Context, filter, replacement interface{}, ...) (*mongo.UpdateResult, error)
- func (model *Base) UpdateId(ctx context.Context, id string, update interface{}, ...) (*mongo.UpdateResult, error)
- func (model *Base) UpdateMany(ctx context.Context, filter, update interface{}, ...) (*mongo.UpdateResult, error)
- func (model *Base) UpdateOne(ctx context.Context, filter, update interface{}, ...) (*mongo.UpdateResult, error)
- func (model *Base) Upsert(ctx context.Context, filter, update interface{}, ...) (*mongo.UpdateResult, error)
- func (model *Base) UpsertId(ctx context.Context, id string, update interface{}, ...) (*mongo.UpdateResult, error)
- func (model *Base) Watch(ctx context.Context, pipeline interface{}, ...) (*mongo.ChangeStream, error)
- type Client
- func GetGlobalClient() Client
- func NewClient(ctx context.Context, config Config) (Client, error)
- func NewClientWithOptions(ctx context.Context, options options.ClientOptions, alias string) (Client, error)
- func NewClientWithURI(ctx context.Context, uri string, alias string) (Client, error)
- func NewGlobalClient(ctx context.Context, config Config) (Client, error)
- type Config
- type Exec
- type Manager
- type Model
- type ModelExec
- type SessionExec
Constants ¶
This section is empty.
Variables ¶
var FilterNil = bson.M{}
Functions ¶
This section is empty.
Types ¶
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
func NewBaseModel ¶
NewBaseModel You can quickly get the initialized Client through ClientManager().Get(alias string), if you use the global Client, you can use GetGlobalClient() to get Client. 可以通过 ClientManager().Get(alias string) 快速获取已初始化的Client, 若使用的全局Client, 则可使用 GetGlobalClient()
func (*Base) BulkWrite ¶
func (model *Base) BulkWrite(ctx context.Context, models []mongo.WriteModel, opts ...*options.BulkWriteOptions) (*mongo.BulkWriteResult, error)
func (*Base) Clone ¶
func (model *Base) Clone(opts ...*options.CollectionOptions) (*mongo.Collection, error)
func (*Base) Collection ¶
func (*Base) CountDocuments ¶
func (*Base) DeleteId ¶
func (model *Base) DeleteId(ctx context.Context, id string, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
func (*Base) DeleteMany ¶
func (model *Base) DeleteMany(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
func (*Base) DeleteOne ¶
func (model *Base) DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
func (*Base) DoWithSession ¶
func (model *Base) DoWithSession(ctx context.Context, exec SessionExec) error
func (*Base) DoWithTransaction ¶
func (*Base) EstimatedDocumentCount ¶
func (*Base) FindOneAndDelete ¶
func (*Base) FindOneAndReplace ¶
func (*Base) FindOneAndUpdate ¶
func (*Base) FindOneAndUpsert ¶
func (*Base) InsertMany ¶
func (model *Base) InsertMany(ctx context.Context, documents []interface{}, opts ...*options.InsertManyOptions) (*mongo.InsertManyResult, error)
func (*Base) InsertOne ¶
func (model *Base) InsertOne(ctx context.Context, document interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)
func (*Base) ReplaceOne ¶
func (model *Base) ReplaceOne(ctx context.Context, filter, replacement interface{}, opts ...*options.ReplaceOptions) (*mongo.UpdateResult, error)
func (*Base) UpdateId ¶
func (model *Base) UpdateId(ctx context.Context, id string, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
func (*Base) UpdateMany ¶
func (model *Base) UpdateMany(ctx context.Context, filter, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
func (*Base) UpdateOne ¶
func (model *Base) UpdateOne(ctx context.Context, filter, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
func (*Base) Upsert ¶
func (model *Base) Upsert(ctx context.Context, filter, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
func (*Base) UpsertId ¶
func (model *Base) UpsertId(ctx context.Context, id string, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
func (*Base) Watch ¶
func (model *Base) Watch(ctx context.Context, pipeline interface{}, opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error)
type Client ¶
type Client interface { Kernel() *mongo.Client Close(ctx context.Context) error Config() Config Do(ctx context.Context, model Model, exec Exec) (interface{}, error) DoWithTransaction(ctx context.Context, model Model, exec Exec) (interface{}, error) DoWithSession(ctx context.Context, model Model, exec SessionExec) error NewBaseModel(database string, collection string) *Base }
func GetGlobalClient ¶
func GetGlobalClient() Client
func NewClient ¶
NewClient If only one db is used, it is recommended to use: NewGlobalClient 若只使用到了一个库,推荐使用: NewGlobalClient
func NewClientWithOptions ¶
func NewClientWithURI ¶
NewClientWithURI uri format: mongodb://username:password@example1.com,example2.com,example3.com/?replicaSet=test&w=majority&wtimeoutMS=5000 Alias is used to specify the client alias. When used, the client can be obtained from the clientMap of the manger through the alias, and ClientManager().Get(alias) can be called alias用于指定client别名,使用时可以通过该别名从manger的clientMap中获取client, 调用 ClientManager().Get(alias)
type Config ¶
type Config struct { Addrs []string `mapstructure:"addrs" json:"addrs"` Auth *Auth `mapstructure:"auth" json:"auth"` ReplicaSetName string `mapstructure:"replica_set_name" json:"replica_set_name"` // Timeout the unit is seconds Timeout time.Duration `mapstructure:"timeout" json:"timeout"` // Mode mgo.Mode `mapstructure:"mode"` PoolLimit uint64 `mapstructure:"pool_limit" json:"pool_limit"` // MaxIdleTime The maximum number of seconds to remain idle in the pool, default 20 minutes MaxIdleTime time.Duration `mapstructure:"max_idle_time" json:"max_idle_time"` AppName string `mapstructure:"app_name" json:"app_name"` //AutoTime bool `mapstructure:"auto_time"` Alias string `mapstructure:"alias" json:"alias"` }
type Exec ¶
type Exec = func(ctx context.Context, collection *mongo.Collection) (interface{}, error)
type Manager ¶
type Manager interface { Add(alias string, c Client) Delete(alias string) Get(alias string) (Client, error) Has(alias string) bool }
func ClientManager ¶
func ClientManager() Manager
type SessionExec ¶
type SessionExec = func(sessionCtx mongo.SessionContext, collection *mongo.Collection) error