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 NewTLSConfig(tlsCfg *TLS) (*tls.Config, bool, 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 TLS
- 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 NewTLSConfig ¶
NewTLSConfig 根据 TLS 配置生成 *tls.Config。
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 *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 设置结构化日志回调(用于接入自有日志系统)。
type TLS ¶
type TLS struct {
// CaCert 为 CA 证书文件路径。
CaCert string `json:"ca_cert"`
// ClientCert 为客户端证书文件路径。
ClientCert string `json:"client_cert"`
// ClientCertKey 为客户端证书私钥文件路径。
ClientCertKey string `json:"client_cert_key"`
}
TLS 描述数据库连接的 TLS(双向)证书配置。
Click to show internal directories.
Click to hide internal directories.