Documentation
¶
Index ¶
- func Delete(ctx context.Context, collection *mongo.Collection, id string) (*mongo.DeleteResult, error)
- func DeleteManyByIds(ctx context.Context, collection *mongo.Collection, ids []string) (*mongo.DeleteResult, error)
- func New(c *Conf) (*mongo.Database, error)
- func NewUUIDv7() string
- func SoftDeleteById(ctx context.Context, collection *mongo.Collection, id string) (*mongo.UpdateResult, error)
- func SoftDeleteManyByIds(ctx context.Context, collection *mongo.Collection, ids []string) (*mongo.UpdateResult, error)
- type Conf
- type Table
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Delete ¶
func Delete(ctx context.Context, collection *mongo.Collection, id string) (*mongo.DeleteResult, error)
DeleteById 按id删除单条文档,并返回 driver 的 DeleteResult。
func DeleteManyByIds ¶
func DeleteManyByIds(ctx context.Context, collection *mongo.Collection, ids []string) (*mongo.DeleteResult, error)
DeleteManyByIds 按id列表批量删除文档,并返回 driver 的 DeleteResult。
func SoftDeleteById ¶
func SoftDeleteById(ctx context.Context, collection *mongo.Collection, id string) (*mongo.UpdateResult, error)
SoftDeleteById 软删除单条文档:写入 updated_at 与 deleted_at,并返回 UpdateResult。
func SoftDeleteManyByIds ¶
func SoftDeleteManyByIds(ctx context.Context, collection *mongo.Collection, ids []string) (*mongo.UpdateResult, error)
SoftDeleteManyByIds 软删除多条文档:批量写入 updated_at 与 deleted_at,并返回 UpdateResult。
Types ¶
type Conf ¶
type Conf struct {
Address string `json:"address"`
Database string `json:"database"`
Username string `json:"username"`
Password string `json:"password"`
// Tls 为 TLS 配置,非空且字段齐全时启用双向 TLS。
Tls *tlsx.TLS `json:"tls"`
// MaxOpenConnects 用于控制连接池最大连接数(映射到 maxPoolSize)。
MaxOpenConnects int `json:"max_open_connects"`
// ConnMaxLifeTime 为连接最大空闲时间(秒),用于回收长时间空闲连接。
ConnMaxLifeTime int `json:"conn_max_life_time"`
// Logger 控制是否启用 Mongo 命令监控日志
Logger bool `json:"logger"`
// contains filtered or unexported fields
}
Conf 定义 MongoDB 连接初始化所需的配置项。
func (*Conf) WithLoggerConsole ¶
WithLoggerConsole 设置是否将日志输出到控制台。
func (*Conf) WithLoggerHandle ¶
WithLoggerHandle 设置结构化日志回调(用于接入自有日志系统)。
Click to show internal directories.
Click to hide internal directories.