Documentation ¶
Index ¶
- Constants
- Variables
- func CountDocuments(arg ...interface{}) (count interface{}, err error)
- func CreateBulkWriteModel(funcArg *FunctionArg) mongo.WriteModel
- func EndTransaction(sessionContext mongo.SessionContext, err error)
- func Find(arg ...interface{}) ([]bson.M, error)
- func FindOne(arg ...interface{}) (exist interface{}, err error)
- func InsertOne(arg ...interface{}) (interface{}, error)
- func NextValue(arg ...interface{}) (singleResult interface{}, err error)
- func StartTransaction(sessionContext mongo.SessionContext) error
- func UpdateMany(arg ...interface{}) (updateResult interface{}, err error)
- func UpdateOne(arg ...interface{}) (updateResult interface{}, err error)
- type FunctionArg
- type Mgr
- func (p *Mgr) Connect(ctx context.Context, opts ...*Options) error
- func (p *Mgr) Disconnect(ctx context.Context) error
- func (p *Mgr) DropDatabase() error
- func (p *Mgr) EnableSharding(ctx context.Context, dbName string) error
- func (p *Mgr) GetClient() *mongo.Client
- func (p *Mgr) GetTimeOutDuration() time.Duration
- func (p *Mgr) IndexesCreateOne(ctx context.Context, collection *mongo.Collection, field string, order int, ...) (newIndexName string, err error)
- func (p *Mgr) IsAbnormal() bool
- func (p *Mgr) SetAbnormal(abnormal bool)
- func (p *Mgr) ShardCollectionHash(ctx context.Context, dbName string, collectionName string, key string, ...) error
- func (p *Mgr) SwitchedCollection(name string) *mongo.Collection
- func (p *Mgr) SwitchedDatabase(name string)
- type Options
- func (p *Options) WithAddrs(addrs []string) *Options
- func (p *Options) WithDBName(dbName *string) *Options
- func (p *Options) WithMaxConnIdleTime(maxConnIdleTime *time.Duration) *Options
- func (p *Options) WithMaxConnecting(maxConnecting *uint64) *Options
- func (p *Options) WithMaxPoolSize(maxPoolSize *uint64) *Options
- func (p *Options) WithMinPoolSize(minPoolSize *uint64) *Options
- func (p *Options) WithPW(pw string) *Options
- func (p *Options) WithTimeoutDuration(timeoutDuration *time.Duration) *Options
- func (p *Options) WithUserName(userName string) *Options
Constants ¶
View Source
const ( StatusNormal uint32 = 0 // 正常状态 StatusAbnormal uint32 = 1 // 异常状态 )
View Source
const ErrorKeyConnectFailure string = "ErrorKeyMongoDBConnectFailure" //Mongo 连接 失败
View Source
const ErrorKeyDisconnectFailure string = "ErrorKeyDisconnectFailure" //Mongo 断开连接 失败
View Source
const ErrorKeyOperateFailure string = "ErrorKeyMongoDBOperateFailure" //Mongo 操作 失败
View Source
const ErrorKeyReadFailure string = "ErrorKeyMongoDBReadFailure" //Mongo 读 失败
View Source
const ErrorKeyWriteFailure string = "ErrorKeyMongoDBWriteFailure" //Mongo 写 失败
View Source
const FuncIDUpdateMany uint32 = 0x302
View Source
const FuncIDUpdateOne uint32 = 0x301
Variables ¶
View Source
var MaxConnIdleTimeDefault = time.Minute * 5
View Source
var MaxConnectingDefault uint64 = 4 // 设置为 P/2
View Source
var MaxPoolSizeDefault uint64 = 24 // 可以设置为 2*P + 30% 的数量
View Source
var MinPoolSizeDefault uint64 = 8 // 可以设置为 P 的数量
View Source
var TimeoutDurationDefault = time.Minute
Functions ¶
func CountDocuments ¶
func CountDocuments(arg ...interface{}) (count interface{}, err error)
CountDocuments 获取文档总数
参数: 0:context.Context 1:*mongo.Collection 2:time.Duration 3:filter interface{} 返回值: count int64 数量
func CreateBulkWriteModel ¶
func CreateBulkWriteModel(funcArg *FunctionArg) mongo.WriteModel
CreateBulkWriteModel FunctionArg转换为BulkWrite的model
func EndTransaction ¶
func EndTransaction(sessionContext mongo.SessionContext, err error)
EndTransaction 结束MongoDB事务
func Find ¶
Find 查找所有文档
参数: 0:context.Context 1:*mongo.Collection 2:time.Duration 3:filter interface{} [4:]:opts ...[]*options.FindOptions 返回值: []bson.M 多个文档数据
func FindOne ¶
func FindOne(arg ...interface{}) (exist interface{}, err error)
FindOne 查找一个文档/查找一个空文档
参数: 0:context.Context 1:*mongo.Collection 2:time.Duration 3:filter interface{} 4:record interface{} [5:]:opts ...[]*options.FindOneOptions 返回值: exist bool 是否有 true:有, false:无
func InsertOne ¶
func InsertOne(arg ...interface{}) (interface{}, error)
InsertOne 插入文档
参数: 0:context.Context 1:*mongo.Collection 2:time.Duration 3:document interface{} [!]不支持[4:]:opts ...*options.InsertOneOptions
func NextValue ¶
func NextValue(arg ...interface{}) (singleResult interface{}, err error)
NextValue 返回更新后的值
参数: 0:context.Context 1:*mongo.Collection 2:time.Duration 3:filter interface{} 4:update interface{} 返回值: singleResult *mongo.SingleResult
func StartTransaction ¶
func StartTransaction(sessionContext mongo.SessionContext) error
StartTransaction 开启MongoDB事务
func UpdateMany ¶
func UpdateMany(arg ...interface{}) (updateResult interface{}, err error)
UpdateMany
参数: 0:context.Context 1:*mongo.Collection 2:time.Duration 3:filter interface{} 4:update interface{} [5:]:opts ...*options.UpdateOptions(目前只支持一个opt-ArrayFilters) 返回值: updateResult *mongo.UpdateResult
Types ¶
type FunctionArg ¶
type FunctionArg struct {
// contains filtered or unexported fields
}
FunctionArg 函数,参数
func CreateFunctionArg ¶
func CreateFunctionArg(collectionName string, collection *mongo.Collection, model mongo.WriteModel, expiration time.Duration) (functionArg *FunctionArg)
CreateFunctionArg BulkWrite的model转换为FunctionArg
func NewFunctionArg ¶
func NewFunctionArg(fun libfuncmgr.Function, funcID uint32, collectionName string, arg ...interface{}) *FunctionArg
NewFunctionArg 构造新的FunctionArg
参数: arg: 0:context.Context 1:*mongo.Collection 2:time.Duration ... 参考 InsertOne, UpdateOne, UpdateMany
func (*FunctionArg) AppendArg ¶
func (p *FunctionArg) AppendArg(i interface{})
func (*FunctionArg) GetArg ¶
func (p *FunctionArg) GetArg() (arg []interface{})
func (*FunctionArg) GetCollectionName ¶
func (p *FunctionArg) GetCollectionName() string
func (*FunctionArg) GetFuncID ¶
func (p *FunctionArg) GetFuncID() uint32
func (*FunctionArg) GetTimeOut ¶
func (p *FunctionArg) GetTimeOut() time.Duration
type Mgr ¶
type Mgr struct {
// contains filtered or unexported fields
}
func (*Mgr) DropDatabase ¶
func (*Mgr) EnableSharding ¶
EnableSharding 启用分片
func (*Mgr) GetTimeOutDuration ¶
GetTimeOutDuration 超时时间
func (*Mgr) IndexesCreateOne ¶
func (p *Mgr) IndexesCreateOne(ctx context.Context, collection *mongo.Collection, field string, order int, unique bool) (newIndexName string, err error)
IndexesCreateOne 创建索引
参数: field:索引字段 order:[1:ascending order 按升序创建索引. -1:descending order 按降序来创建索引] unique: 建立的索引是否唯一.指定为true创建唯一索引.默认值为false
func (*Mgr) SetAbnormal ¶
SetAbnormal 设置异常 false:正常 true:异常
func (*Mgr) ShardCollectionHash ¶
func (p *Mgr) ShardCollectionHash(ctx context.Context, dbName string, collectionName string, key string, numInitialChunks int) error
ShardCollectionHash 分片数据集-hash
参数: numInitialChunks:chuck数量 e.g.:1024
func (*Mgr) SwitchedCollection ¶
func (p *Mgr) SwitchedCollection(name string) *mongo.Collection
func (*Mgr) SwitchedDatabase ¶
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options contains options to configure a server instance. Each option can be set through setter functions. See documentation for each setter function for an explanation of the option.
func (*Options) WithDBName ¶
func (*Options) WithMaxConnIdleTime ¶
func (*Options) WithMaxConnecting ¶
func (*Options) WithMaxPoolSize ¶
func (*Options) WithMinPoolSize ¶
func (*Options) WithTimeoutDuration ¶
func (*Options) WithUserName ¶
Click to show internal directories.
Click to hide internal directories.