mongodb

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(cfg *Config) (*mongo.Client, error)

NewClient 创建原生 MongoDB 客户端 (go.mongodb.org/mongo-driver)

func NewDatabase

func NewDatabase(client *mgo.Client, cfg *Config) *mgo.Database

NewDatabase 创建 gocrud/mgo Database 对象

func NewMgoClient

func NewMgoClient(cfg *Config) (*mgo.Client, error)

NewMgoClient 创建 gocrud/mgo 封装的 Client (推荐) 它提供了链式调用、软删除、Hooks 等高级功能

Types

type Config

type Config struct {
	URI      string `yaml:"uri"`
	Database string `yaml:"database"`
}

Config MongoDB 配置

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager 管理 MongoDB 连接的生命周期

func NewManager

func NewManager(client *mgo.Client) *Manager

NewManager 创建连接管理器

func (*Manager) Name

func (m *Manager) Name() string

Name 组件名称

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start 启动 (MongoDB 连接在 NewClient 时已建立,此处可做健康检查)

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context) error

Stop 优雅关闭连接

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL