mongodb

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 13 Imported by: 0

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

View Source
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

func NewClient(cfg config.MongoDBConfig, logger *zap.Logger) (*Client, error)

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) Close

func (c *Client) Close(ctx context.Context) error

Close disconnects the MongoDB client gracefully.

func (*Client) Collection

func (c *Client) Collection(name string) *mongo.Collection

Collection is a convenience shortcut for Database().Collection(name).

func (*Client) Database

func (c *Client) Database() *mongo.Database

Database returns the default *mongo.Database.

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.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping checks MongoDB connectivity.

Jump to

Keyboard shortcuts

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