Documentation
¶
Index ¶
- func GetMongoUrl(setting Setting) string
- func MonMongoPlugin(ctx context.Context, doc interface{}, opType operator.OpType, ...) error
- func NewInsertManyMonOpt(database, collection string) options.InsertManyOptions
- func NewInsertMonOpt(database, collection string) options.InsertOneOptions
- func NewQueryMonOpt(database, collection string) options.FindOptions
- func NewRemoveMonOpt(database, collection string) options.RemoveOptions
- func NewReplaceMonOpt(database, collection string) options.ReplaceOptions
- func NewUpdateMonOpt(database, collection string) options.UpdateOptions
- func NewUpsertMonOpt(database, collection string) options.UpsertOptions
- type Auth
- type MonMongoHook
- type Setting
- type WrapperMongo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetMongoUrl ¶
func MonMongoPlugin ¶
func MonMongoPlugin(ctx context.Context, doc interface{}, opType operator.OpType, opts ...interface{}) error
MonMongoPlugin mon打点插件。其中的doc或者opt中必须传指针类型的
func NewInsertManyMonOpt ¶
func NewInsertManyMonOpt(database, collection string) options.InsertManyOptions
func NewInsertMonOpt ¶
func NewInsertMonOpt(database, collection string) options.InsertOneOptions
NewInsertMonOpt 使用时将其放置到Insert的opt中 示例:cli.InsertOne(ctx, UserInfo{}, mongo.NewInsertMonOpt("test_db", "test_collection"))
func NewQueryMonOpt ¶
func NewQueryMonOpt(database, collection string) options.FindOptions
NewQueryMonOpt 使用时将其放置到Find的opt中 示例: cli := WrapperMongo.Client.Database("test_db").Collection("test_collection")
cli.Find(ctx, bson.M{"_id": objId}, mongo.NewQueryMonOpt("test_db", "test_collection")).One(&res)
func NewRemoveMonOpt ¶
func NewRemoveMonOpt(database, collection string) options.RemoveOptions
func NewReplaceMonOpt ¶
func NewReplaceMonOpt(database, collection string) options.ReplaceOptions
func NewUpdateMonOpt ¶
func NewUpdateMonOpt(database, collection string) options.UpdateOptions
func NewUpsertMonOpt ¶
func NewUpsertMonOpt(database, collection string) options.UpsertOptions
Types ¶
type Auth ¶
type Auth struct { // AuthMechanism: the mechanism to use for authentication. Supported values include "SCRAM-SHA-256", "SCRAM-SHA-1", // "MONGODB-CR", "PLAIN", "GSSAPI", "MONGODB-X509", and "MONGODB-AWS". This can also be set through the "authMechanism" // 一般情况 "SCRAM-SHA-256", "SCRAM-SHA-1" AuthMechanism string `mapstructure:"auth_mechanism"` // AuthSource: the name of the database to use for authentication. This defaults to "$external" for MONGODB-X509, // GSSAPI, and PLAIN and "admin" for all other mechanisms. This can also be set through the "authSource" URI option // 一般情况上为admin AuthSource string `mapstructure:"auth_source"` Username string `mapstructure:"username"` Password string `mapstructure:"password"` // PasswordSet对于对于GSSAPI生效,其它此字段被忽略 PasswordSet bool `mapstructure:"password_set"` }
type MonMongoHook ¶
func (*MonMongoHook) After ¶
func (p *MonMongoHook) After() error
func (*MonMongoHook) Before ¶
func (p *MonMongoHook) Before() error
type Setting ¶
type Setting struct { Name string `mapstructure:"name"` // shading或者replica_set,默认replica_set Type string `mapstructure:"type"` // 地址,不能为空 Addr []string `mapstructure:"addr"` // primary、primaryPreferred、secondary、secondaryPreferred、nearest // 默认nearest ReadPreferenceMode string `mapstructure:"read_preference_mode"` //mongodb版本必须大于3.4才能设置,否侧报错,默认0即可 MaxStalenessMS int64 `mapstructure:"max_staleness_ms"` // 最大连接数量,默认5 MaxPoolSize uint64 `mapstructure:"max_pool_size"` // 最小连接数量,默认2 MinPoolSize uint64 `mapstructure:"minPoolSize"` // 连接超时时间,默认2000ms ConnectTimeoutMs int64 `mapstructure:"connect_timeout_ms"` // 操作超时时间,默认200ms SocketTimeoutMS int64 `mapstructure:"socket_timeout_ms"` // 权限 Auth *Auth `mapstructure:"auth"` }
type WrapperMongo ¶
func InitMongo ¶
func InitMongo(setting Setting, middleware ...callback) (*WrapperMongo, error)
InitMongo 返回mongo连接池实例 用法:mongoPool.Client.Database("test_db").Collection("test_collection").
Find(ctx, bson.M{"_id": objId}). One(&res)
依赖Qmgo,文档地址:https://github.com/qiniu/qmgo
Click to show internal directories.
Click to hide internal directories.