Documentation
¶
Index ¶
- func IsNotFoundError(err error) bool
- func IsUniqueConstraintError(err error) bool
- type AutoIDModel
- type Coll
- type Collection
- type Filter
- type IDPool
- type MapStr
- type Mongo
- func (m *Mongo) Collection(collName string) *mongo.Collection
- func (m *Mongo) Collections(collName string) Collection
- func (m *Mongo) Database() *mongo.Database
- func (m *Mongo) GetBatchIdGenerator(collection string, count int) (startID int64, err error)
- func (m *Mongo) GetIdGenerator(collection string) int64
- func (m *Mongo) InsertManyWithAutoID(ctx context.Context, collectionName string, docs []AutoIDModel) (*mongo.InsertManyResult, error)
- func (m *Mongo) InsertOneWithAutoID(ctx context.Context, collectionName string, doc AutoIDModel) (*mongo.InsertOneResult, error)
- type Querier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNotFoundError ¶ added in v1.10.0
IsNotFoundError 检查是否是数据不存在错误
func IsUniqueConstraintError ¶ added in v1.10.0
IsUniqueConstraintError 检查是否是唯一索引冲突错误
Types ¶
type AutoIDModel ¶ added in v1.10.0
AutoIDModel 定义需要自动生成 ID 的模型接口
type Collection ¶
type Collection interface {
Where()
}
type IDPool ¶ added in v1.10.0
type IDPool struct {
// contains filtered or unexported fields
}
IDPool ID池,用于高并发场景的性能优化
func NewIDPoolWithRange ¶ added in v1.10.0
NewIDPoolWithRange 创建带自定义范围的ID池
func (*IDPool) Close ¶ added in v1.10.0
Close 优雅关闭ID池 尝试将未使用的ID归还到数据库(可选,用于减少浪费) 注意:这个操作有风险,只在优雅关闭时调用,crash时无法执行
type Mongo ¶
type Mongo struct {
DBClient *mongo.Client
Sess mongo.Session
// contains filtered or unexported fields
}
func (*Mongo) Collection ¶
func (m *Mongo) Collection(collName string) *mongo.Collection
func (*Mongo) Collections ¶
func (m *Mongo) Collections(collName string) Collection
func (*Mongo) GetBatchIdGenerator ¶ added in v1.10.0
GetBatchIdGenerator 批量获取自增 ID,提高批量插入性能
func (*Mongo) GetIdGenerator ¶
func (*Mongo) InsertManyWithAutoID ¶ added in v1.10.0
func (m *Mongo) InsertManyWithAutoID(ctx context.Context, collectionName string, docs []AutoIDModel) (*mongo.InsertManyResult, error)
InsertManyWithAutoID 批量插入文档,自动生成 ID(性能优化版)
func (*Mongo) InsertOneWithAutoID ¶ added in v1.10.0
func (m *Mongo) InsertOneWithAutoID(ctx context.Context, collectionName string, doc AutoIDModel) (*mongo.InsertOneResult, error)
InsertOneWithAutoID 插入单个文档,自动生成 ID
Click to show internal directories.
Click to hide internal directories.