mongostore

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mongostore is the flag source of a MongoDB database: a flag file is one collection, read with one find, and the store answers with a virtual flag file that it builds from the documents of the collection (one flag for each document, the way GO Feature Flag stores them). It is the only package of the flag sources that imports the MongoDB driver.

Index

Constants

View Source
const (
	// KeySuffix ends the key of a flag set: the collection is the key without it.
	KeySuffix = ".json"
)

Variables

View Source
var (
	// ErrURI is the cause of a URI that the driver cannot parse. The cause of the driver is dropped: it may quote a
	// part of the URI.
	ErrURI = fmt.Errorf("%w: the URI cannot be parsed", objectstore.ErrInvalidConfig)
	// ErrTLS is the cause of a TLS setting that cannot be used (a CA bundle that holds no certificate).
	ErrTLS = fmt.Errorf("%w: the TLS setting cannot be used", objectstore.ErrInvalidConfig)
	// ErrClient is the cause of a client that the driver cannot build from the setting.
	ErrClient = fmt.Errorf("%w: the MongoDB client cannot be built", objectstore.ErrInvalidConfig)
	// ErrKeyRefused is the cause of a key that is no collection name followed by ".json".
	ErrKeyRefused = errors.New("objectstore: the key is no collection name with the .json suffix")
	// ErrAccessRefused is the cause of an answer that refuses the credentials or the permission (an authentication
	// error, or "not authorized").
	ErrAccessRefused = errors.New("objectstore: MongoDB access refused")
	// ErrUnavailable is the cause of every other failure of the database: no server, a lost connection, a command
	// error. The driver error is dropped: it names the hosts.
	ErrUnavailable = errors.New("objectstore: MongoDB is not available")
)

The causes of a refused setting or key. None of them holds a host, a name or a credential.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Tracing are the OpenTelemetry providers of the store: with them enabled every command has a client span, from the
	// stock instrumentation of the driver (otelmongo). The span carries the database, the collection, the command name
	// and the address of the server; never the command, a filter or a document, and never the URI. The zero value
	// instruments nothing.
	Tracing tracing.Providers
	// Logger receives the one line about documents that are not flags. Nil discards it.
	Logger *slog.Logger
	// URI is the connection string. It holds the user and the password, and is never printed.
	URI storekit.Secret
	// Database is the database that holds the collections.
	Database string
	// CABundlePEM are the certificate authorities that sign the server, instead of the system roots. It turns TLS on.
	CABundlePEM []byte
	// MinTLSVersion is the lowest TLS version of a TLS connection; zero means TLS 1.2.
	MinTLSVersion uint16
	// RequestTimeout bounds one Get from the request to the last document. Zero means
	// [storekit.DefaultCloudRequestTimeout].
	RequestTimeout time.Duration
}

Config is the setting of a Store.

type Store

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

Store is an objectstore.ObjectStore on the collections of one MongoDB database. A key is the name of a collection and ".json" (flags.json reads the collection flags); the store answers with one JSON document, the flag file, built from every document of the collection. See Store.Get for the rules.

func New

func New(ctx context.Context, cfg *Config) (*Store, error)

New checks the setting and returns the store. The driver starts to monitor the servers in the background; no command is sent before the first Get. ctx is for the start of the client only: the reads take their own.

func (*Store) Close

func (s *Store) Close() error

Close disconnects from the servers.

func (*Store) CloseIdleConnections

func (*Store) CloseIdleConnections()

CloseIdleConnections does nothing: the driver owns its pool and closes the idle connections by itself.

func (*Store) CollectionOf

func (s *Store) CollectionOf(key string) (string, bool)

CollectionOf is the collection of a key, and false for a key that names none: the key is the name of the collection and KeySuffix.

func (*Store) Format

func (s *Store) Format(f fmt.State, _ rune)

Format implements fmt.Formatter: every verb prints the database and nothing of the setting.

func (*Store) Get

Get implements objectstore.ObjectStore. The answer is the flag file of the collection.

  • The ETag is the SHA-256 of that document, so an unchanged collection is objectstore.ErrNotModified. The document is rebuilt with its names in order: documents that differ only in the order of their fields, or in the order they are read, give the same ETag.
  • MongoDB keeps no modification time for a collection, and the time of a replica would differ between readers: Modified is the zero time, the same for every reader.
  • A collection that does not exist is objectstore.ErrNotFound; one that exists and holds no document is the empty flag set.
  • The collection is read with one find, sorted by _id, in the one consistent view the server gives that command. A change while the batches are read can tear the answer; the next poll reads the new state.

Jump to

Keyboard shortcuts

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