Help us shape the future of Go! Take the 2026 Go Developer Survey

mongoadmin

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package mongoadmin implements authenticated, quorum-aware MongoDB administration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddNonVoting

func AddNonVoting(ctx context.Context, c *mongo.Client, id int, host string) error

AddNonVoting adds one member without changing the voting majority.

func AddShard

func AddShard(ctx context.Context, c *mongo.Client, set, hosts string) error

AddShard registers a shard idempotently using its replica-set connection string.

func Balancer

func Balancer(ctx context.Context, c *mongo.Client) (string, bool, error)

Balancer reads enabled/running state from mongos.

func CheckWritablePrimary added in v0.2.0

func CheckWritablePrimary(ctx context.Context, c *mongo.Client) error

CheckWritablePrimary selects the primary and verifies its current hello response, rather than treating a successful nearest/secondary ping as writable.

func Dial

func Dial(ctx context.Context, o DialOptions) (*mongo.Client, error)

Dial connects and verifies that the authenticated endpoint responds.

func FCV

func FCV(ctx context.Context, c *mongo.Client) (string, error)

FCV reads the current feature compatibility version.

func Promote

func Promote(ctx context.Context, c *mongo.Client, host string) error

Promote votes a caught-up secondary, changing only one vote per reconfig.

func ReadError added in v0.2.0

func ReadError(err error) error

ReadError classifies temporary database connectivity/topology failures without changing authentication, authorization or non-transient command errors. mongo.IsNetworkError and mongo.IsTimeout inspect wrapped errors and labels; driver.Error.RetryableRead supplies the driver's transient read code set.

func Remove

func Remove(ctx context.Context, c *mongo.Client, host string) error

Remove removes a non-primary only when the existing majority remains healthy.

func SafeToRestart

func SafeToRestart(ctx context.Context, c *mongo.Client, host string) error

SafeToRestart refuses a restart that would leave no healthy voting majority.

func SetBalancer

func SetBalancer(ctx context.Context, c *mongo.Client, enabled bool) error

SetBalancer changes balancer operation on a mongos.

func SetFCV

func SetFCV(ctx context.Context, c *mongo.Client, version string) error

SetFCV explicitly raises feature compatibility after binary upgrades.

func StepDown

func StepDown(ctx context.Context, c *mongo.Client) error

StepDown transfers primary ownership without forcing an unsafe election.

Types

type Config

type Config struct {
	ID      string         `bson:"_id"`
	Version int            `bson:"version"`
	Members []ConfigMember `bson:"members"`
	Extra   bson.M         `bson:",inline"`
}

Config preserves additional server-side configuration fields during reconfiguration.

func GetConfig

func GetConfig(ctx context.Context, c *mongo.Client) (Config, error)

GetConfig reads the current configuration from the primary.

type ConfigMember

type ConfigMember struct {
	ID       int     `bson:"_id"`
	Host     string  `bson:"host"`
	Priority float64 `bson:"priority"`
	Votes    int     `bson:"votes"`
	Extra    bson.M  `bson:",inline"`
}

ConfigMember is a replica-set configuration entry.

type DialOptions

type DialOptions struct {
	Hosts              []string
	ReplicaSet         string
	Direct             bool
	Username, Password string
	CAPEM              []byte
	TLS                bool
	Timeout            time.Duration
	Dialer             options.ContextDialer
}

DialOptions selects server discovery, authentication and certificate verification.

type Member

type Member struct {
	ID         int       `bson:"_id"`
	Name       string    `bson:"name"`
	State      string    `bson:"stateStr"`
	Health     float64   `bson:"health"`
	Uptime     int64     `bson:"uptime"`
	OptimeDate time.Time `bson:"optimeDate"`
}

Member is an observed replica-set member.

type Status

type Status struct {
	Set     string   `bson:"set"`
	Members []Member `bson:"members"`
}

Status is the server's replica-set status response.

func GetObservedStatus added in v0.2.0

func GetObservedStatus(ctx context.Context, c *mongo.Client, host string) (Status, error)

GetObservedStatus bounds one replication read without shortening subsequent administrative commands.

func GetPrimaryStatus added in v0.2.0

func GetPrimaryStatus(ctx context.Context, c *mongo.Client) (Status, error)

GetPrimaryStatus uses the writable side's replication view. A partitioned secondary's nearest-server view must not label reachable primary peers dead.

func GetStatus

func GetStatus(ctx context.Context, c *mongo.Client) (Status, error)

GetStatus retrieves replication roles and optimes.

func (Status) HasWritablePrimary added in v0.2.0

func (s Status) HasWritablePrimary() bool

HasWritablePrimary rejects secondary-only and contradictory replication views.

func (Status) Lag

func (s Status) Lag(m Member) float64

Lag reports seconds behind the newest optime in this replica set.

Jump to

Keyboard shortcuts

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