mongo

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package mongo implements a deliberately tiny MongoDB client: just enough OP_MSG + BSON to run administrative commands (hello, replSetInitiate, addShard, ...) against unauthenticated sandbox instances launched by mlaunch-go. It has no external dependencies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WaitForPrimary

func WaitForPrimary(addrs []string, deadline time.Duration) (string, error)

WaitForPrimary polls the members until one of them reports being a writable primary.

func WaitReachable

func WaitReachable(addr string, deadline time.Duration) error

WaitReachable polls addr until a `ping` succeeds or the deadline passes.

Types

type A

type A []any

A is a BSON array.

type Client

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

Client is a single-connection MongoDB client.

func Dial

func Dial(addr string, timeout time.Duration) (*Client, error)

Dial connects to addr ("host:port").

func (*Client) Authenticate

func (c *Client) Authenticate(authDB, user, password string) error

Authenticate performs a SCRAM-SHA-256 (RFC 7677) conversation on the connection for the given user in the given auth database (usually "admin"). Implemented with stdlib crypto only.

func (*Client) Close

func (c *Client) Close() error

func (*Client) RunCommand

func (c *Client) RunCommand(db string, cmd D) (M, error)

RunCommand executes cmd against db and returns the reply document. The command name must be the first element of cmd.

type CommandError

type CommandError struct{ Reply M }

CommandError is returned when the server replies with ok != 1.

func (*CommandError) Error

func (e *CommandError) Error() string

type D

type D []E

D is an ordered BSON document. Order matters for MongoDB commands: the command name must be the first element.

type E

type E struct {
	Key string
	Val any
}

E is a single BSON element.

type M

type M map[string]any

M is an unordered decoded document.

Jump to

Keyboard shortcuts

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