Documentation ¶
Index ¶
- type BulkWriteOptions
- type FieldMapping
- type MongoDB
- type MongoDBImpl
- func (m *MongoDBImpl) BulkWriteWithRetry(ctx context.Context, opts *BulkWriteOptions) error
- func (m *MongoDBImpl) GetBatchPool() *pool.BatchPool[pool.BSONBatch]
- func (m *MongoDBImpl) GetClient() *mongo.Client
- func (m *MongoDBImpl) InitBatchPool(poolSize int)
- func (m *MongoDBImpl) ReadByPage(ctx context.Context, params PaginatedQueryParams) ([]bson.M, error)
- func (m *MongoDBImpl) SetPoolSize(defaultPoolSize int)
- type PaginatedQueryParams
- type RenameOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BulkWriteOptions ¶
type BulkWriteOptions struct { DbName string // 数据库名称 CollName string // 集合名称 Documents []*bson.M // 要写入的文档指针数组 RetryPolicy retry.RetryPolicy // 重试策略接口 }
BulkWriteOptions 封装了BulkWriteWithRetry函数所需的参数
type MongoDB ¶
type MongoDB interface { // ReadByPage 读取mongo指定集合表中指定分页的数据 ReadByPage(ctx context.Context, params PaginatedQueryParams) ([]bson.M, error) // BulkWriteWithRetry 带有重试策略的批量写操作 BulkWriteWithRetry(ctx context.Context, opts *BulkWriteOptions) error }
MongoDB mongo接口定义
type MongoDBImpl ¶
type MongoDBImpl struct {
// contains filtered or unexported fields
}
MongoDBImpl mongo的具体实例
func GetMongoDBInstance ¶
func GetMongoDBInstance(ctx context.Context, retryPolicy retry.RetryPolicy, basic *options.ClientOptions, opts ...func(*options.ClientOptions), ) (*MongoDBImpl, error)
GetMongoDBInstance 单例方式初始化 MongoDB 实例
func (*MongoDBImpl) BulkWriteWithRetry ¶
func (m *MongoDBImpl) BulkWriteWithRetry(ctx context.Context, opts *BulkWriteOptions) error
BulkWriteWithRetry 带有重试策略的批量写
func (*MongoDBImpl) GetBatchPool ¶
func (m *MongoDBImpl) GetBatchPool() *pool.BatchPool[pool.BSONBatch]
GetBatchPool 返回批处理对象池
func (*MongoDBImpl) GetClient ¶
func (m *MongoDBImpl) GetClient() *mongo.Client
GetClient 返回mongo的client
func (*MongoDBImpl) InitBatchPool ¶
func (m *MongoDBImpl) InitBatchPool(poolSize int)
InitBatchPool 初始化对象池
func (*MongoDBImpl) ReadByPage ¶
func (m *MongoDBImpl) ReadByPage(ctx context.Context, params PaginatedQueryParams) ([]bson.M, error)
ReadByPage 读取指定页码的数据
func (*MongoDBImpl) SetPoolSize ¶
func (m *MongoDBImpl) SetPoolSize(defaultPoolSize int)
SetPoolSize 设置连接池大小
type PaginatedQueryParams ¶
PaginatedQueryParams 分页读取的选项
func (*PaginatedQueryParams) Validate ¶
func (p *PaginatedQueryParams) Validate() error
Validate 验证PaginatedQueryParams的字段是否已被正确设置
type RenameOption ¶
type RenameOption struct { Mapping FieldMapping KeepOriginal bool // 是否保留原始字段 }
RenameOption 定义重命名选项
Click to show internal directories.
Click to hide internal directories.