Documentation ¶
Index ¶
- func BeforeCreate(document any) any
- func BeforeUpdate(document any) any
- func Caller(skip int) map[string]string
- func SetSlowThreshold(threshold time.Duration)
- type DecoratedCollection
- func (c *DecoratedCollection) Aggregate(ctx context.Context, pipeline any, result any) (err error)
- func (c *DecoratedCollection) Count(ctx context.Context) (result int64, err error)
- func (c *DecoratedCollection) CreateIndex(ctx context.Context, key bson.D, op *options.IndexOptions) (res string, err error)
- func (c *DecoratedCollection) Delete(ctx context.Context) (count int64, err error)
- func (c *DecoratedCollection) Drop(ctx context.Context) (err error)
- func (c *DecoratedCollection) DropIndex(ctx context.Context, name string, opts *options.DropIndexesOptions) (err error)
- func (c *DecoratedCollection) Fields(fields bson.M) *DecoratedCollection
- func (c *DecoratedCollection) FindMany(ctx context.Context, documents any) (err error)
- func (c *DecoratedCollection) FindOne(ctx context.Context, document any) (err error)
- func (c *DecoratedCollection) InsertMany(ctx context.Context, documents any) (val *mongo.InsertManyResult, err error)
- func (c *DecoratedCollection) InsertOne(ctx context.Context, document any) (val *mongo.InsertOneResult, err error)
- func (c *DecoratedCollection) Limit(n int64) *DecoratedCollection
- func (c *DecoratedCollection) ListIndexes(ctx context.Context, opts *options.ListIndexesOptions) (val []string, err error)
- func (c *DecoratedCollection) Skip(n int64) *DecoratedCollection
- func (c *DecoratedCollection) Sort(sorts bson.D) *DecoratedCollection
- func (c *DecoratedCollection) UpdateMany(ctx context.Context, document any) (val *mongo.UpdateResult, err error)
- func (c *DecoratedCollection) UpdateOne(ctx context.Context, document any) (val *mongo.UpdateResult, err error)
- func (c *DecoratedCollection) UpdateOneRaw(ctx context.Context, document any, opt ...*options.UpdateOptions) (val *mongo.UpdateResult, err error)
- func (c *DecoratedCollection) UpdateOrInsert(ctx context.Context, documents []any) (val *mongo.UpdateResult, err error)
- func (c *DecoratedCollection) Where(m bson.D) *DecoratedCollection
- type Model
- type MongoDB
- func (cs *MongoDB) Close() error
- func (m *MongoDB) MustNewCollection(collection string) *DecoratedCollection
- func (m *MongoDB) MustNewModel(collection string) *Model
- func (m *MongoDB) NewCollection(collection string) (*DecoratedCollection, error)
- func (m *MongoDB) NewModel(collection string) (*Model, error)
- func (m *MongoDB) Ping() error
- func (m *MongoDB) SetDisableMetric(disableMetric bool) *MongoDB
- func (m *MongoDB) SetDisableTrace(disableTrace bool) *MongoDB
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetSlowThreshold ¶ added in v3.4.4
SetSlowThreshold sets the slow threshold.
Types ¶
type DecoratedCollection ¶ added in v3.4.4
type DecoratedCollection struct { *mongo.Collection DisableMetric bool // 关闭指标采集 DisableTrace bool // 关闭链路追踪 // contains filtered or unexported fields }
func (*DecoratedCollection) Count ¶ added in v3.4.4
func (c *DecoratedCollection) Count(ctx context.Context) (result int64, err error)
Count ...
func (*DecoratedCollection) CreateIndex ¶ added in v3.4.4
func (c *DecoratedCollection) CreateIndex(ctx context.Context, key bson.D, op *options.IndexOptions) (res string, err error)
CreateIndex CreateOneIndex 创建单个普通索引
func (*DecoratedCollection) Delete ¶ added in v3.4.4
func (c *DecoratedCollection) Delete(ctx context.Context) (count int64, err error)
Delete 删除数据,并返回删除成功的数量
func (*DecoratedCollection) Drop ¶ added in v3.4.4
func (c *DecoratedCollection) Drop(ctx context.Context) (err error)
Drop ...
func (*DecoratedCollection) DropIndex ¶ added in v3.4.4
func (c *DecoratedCollection) DropIndex(ctx context.Context, name string, opts *options.DropIndexesOptions) (err error)
DropIndex 删除索引
func (*DecoratedCollection) Fields ¶ added in v3.4.4
func (c *DecoratedCollection) Fields(fields bson.M) *DecoratedCollection
Fields 指定查询字段
func (*DecoratedCollection) FindMany ¶ added in v3.4.4
func (c *DecoratedCollection) FindMany(ctx context.Context, documents any) (err error)
FindMany 查询多条数据
func (*DecoratedCollection) FindOne ¶ added in v3.4.4
func (c *DecoratedCollection) FindOne(ctx context.Context, document any) (err error)
FindOne 查询一条数据
func (*DecoratedCollection) InsertMany ¶ added in v3.4.4
func (c *DecoratedCollection) InsertMany(ctx context.Context, documents any) (val *mongo.InsertManyResult, err error)
InsertMany 写入多条数据
func (*DecoratedCollection) InsertOne ¶ added in v3.4.4
func (c *DecoratedCollection) InsertOne(ctx context.Context, document any) (val *mongo.InsertOneResult, err error)
InsertOne 写入单条数据
func (*DecoratedCollection) Limit ¶ added in v3.4.4
func (c *DecoratedCollection) Limit(n int64) *DecoratedCollection
Limit 限制条数
func (*DecoratedCollection) ListIndexes ¶ added in v3.4.4
func (c *DecoratedCollection) ListIndexes(ctx context.Context, opts *options.ListIndexesOptions) (val []string, err error)
ListIndexes 获取所有所有
func (*DecoratedCollection) Skip ¶ added in v3.4.4
func (c *DecoratedCollection) Skip(n int64) *DecoratedCollection
Skip 跳过条数
func (*DecoratedCollection) Sort ¶ added in v3.4.4
func (c *DecoratedCollection) Sort(sorts bson.D) *DecoratedCollection
Sort 排序 bson.M{"created_at":-1}
func (*DecoratedCollection) UpdateMany ¶ added in v3.4.4
func (c *DecoratedCollection) UpdateMany(ctx context.Context, document any) (val *mongo.UpdateResult, err error)
UpdateMany ...
func (*DecoratedCollection) UpdateOne ¶ added in v3.4.4
func (c *DecoratedCollection) UpdateOne(ctx context.Context, document any) (val *mongo.UpdateResult, err error)
UpdateOne ...
func (*DecoratedCollection) UpdateOneRaw ¶ added in v3.4.4
func (c *DecoratedCollection) UpdateOneRaw(ctx context.Context, document any, opt ...*options.UpdateOptions) (val *mongo.UpdateResult, err error)
UpdateOneRaw 原生update
func (*DecoratedCollection) UpdateOrInsert ¶ added in v3.4.4
func (c *DecoratedCollection) UpdateOrInsert(ctx context.Context, documents []any) (val *mongo.UpdateResult, err error)
UpdateOrInsert 存在更新,不存在写入, documents 里边的文档需要有 _id 的存在
func (*DecoratedCollection) Where ¶ added in v3.4.4
func (c *DecoratedCollection) Where(m bson.D) *DecoratedCollection
Where 条件查询, bson.M{"field": "value"}
type Model ¶ added in v3.4.4
type Model struct { Collection *DecoratedCollection // contains filtered or unexported fields }
MongoDB wraps *mongo.Client and provides a Close method.
type MongoDB ¶
type MongoDB struct { *mongo.Client DisableMetric bool // 关闭指标采集 DisableTrace bool // 关闭链路追踪 Name string // 数据库名称 Uri string }
MongoDB wraps *mongo.Client and provides a Close method.
func NewMongoDBClient ¶ added in v3.4.4
NewMongoDBClient
func (*MongoDB) MustNewCollection ¶ added in v3.4.4
func (m *MongoDB) MustNewCollection(collection string) *DecoratedCollection
func (*MongoDB) MustNewModel ¶ added in v3.4.4
MustNewModel returns a Model, exits on errors.
func (*MongoDB) NewCollection ¶ added in v3.4.4
func (m *MongoDB) NewCollection(collection string) (*DecoratedCollection, error)
func (*MongoDB) SetDisableMetric ¶ added in v3.4.4
func (*MongoDB) SetDisableTrace ¶ added in v3.4.4
type Option ¶ added in v3.4.4
type Option func(opts *options.ClientOptions)
Option defines the method to customize a mongo model.
func WithMaxConnIdleTime ¶ added in v3.4.4
WithMaxConnIdleTime set the mon client max connection idle time.
func WithMaxPoolSize ¶ added in v3.4.4
WithMaxPoolSize set the mon client max pool size.
func WithMinPoolSize ¶ added in v3.4.4
WithMinPoolSize set the mon client min pool size.
func WithTimeout ¶ added in v3.4.4
WithTimeout set the mon client operation timeout.