Documentation
¶
Overview ¶
Package mongodb provides MongoDB client management for agentflow.
Supports connection pooling, health checks, and graceful shutdown, mirroring the patterns in pkg/database/pool.go.
Index ¶
- Constants
- func BuildClientOptions(cfg config.MongoDBConfig) (*options.ClientOptions, error)
- type Client
- func (c *Client) Close(ctx context.Context) error
- func (c *Client) Collection(name string) *mongo.Collection
- func (c *Client) Database() *mongo.Database
- func (c *Client) EnsureIndexes(ctx context.Context, collName string, models []mongo.IndexModel) error
- func (c *Client) Ping(ctx context.Context) error
Constants ¶
const DefaultHealthCheckInterval = 30 * time.Second
DefaultHealthCheckInterval is used when the config value is zero.
Variables ¶
This section is empty.
Functions ¶
func BuildClientOptions ¶
func BuildClientOptions(cfg config.MongoDBConfig) (*options.ClientOptions, error)
BuildClientOptions converts a config.MongoDBConfig into mongo driver options.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the MongoDB driver client with health checks and graceful shutdown. Mirrors the patterns in pkg/database/pool.go.
func NewClient ¶
NewClient creates a new MongoDB client, pings the server, and starts a background health-check goroutine.
func NewClientFromOptions ¶
func NewClientFromOptions(opts *options.ClientOptions, dbName string, logger *zap.Logger) (*Client, error)
NewClientFromOptions creates a Client from pre-built driver options. Useful for testing with custom options.
func (*Client) Collection ¶
func (c *Client) Collection(name string) *mongo.Collection
Collection is a convenience shortcut for Database().Collection(name).
func (*Client) EnsureIndexes ¶
func (c *Client) EnsureIndexes(ctx context.Context, collName string, models []mongo.IndexModel) error
EnsureIndexes creates indexes on the given collection. Intended to be called once during application startup.