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 ¶
const (
// KeySuffix ends the key of a flag set: the collection is the key without it.
KeySuffix = ".json"
)
Variables ¶
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") // 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 ¶
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) CloseIdleConnections ¶
func (*Store) CloseIdleConnections()
CloseIdleConnections does nothing: the driver owns its pool and closes the idle connections by itself.
func (*Store) CollectionOf ¶
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 ¶
Format implements fmt.Formatter: every verb prints the database and nothing of the setting.
func (*Store) Get ¶
func (s *Store) Get(ctx context.Context, req objectstore.GetRequest) (objectstore.Object, error)
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.