Skip to main content

MongoDB Plugin

lynx-mongodb is the runtime-owned MongoDB client for Lynx. This page documents the fields that appear in lynx-mongodb/conf/example_config.yml, including when each key matters, how defaults behave, and where users commonly misread the template.

Runtime Facts

ItemValue
Go modulegithub.com/go-lynx/lynx-mongodb
Config prefixlynx.mongodb
Runtime plugin namemongodb.client
Public gettersGetMongoDB(), GetMongoDBDatabase(), GetMongoDBCollection(name), GetMetricsGatherer(), GetMongoDBPlugin()

Template Field Guide

FieldWhat it controlsEnable whenDefault / interactionCommon misconfig
uriBase MongoDB connection URI.Always.Default "mongodb://localhost:27017". Replica-set, sharded, or SRV options still live inside this URI.Splitting one deployment's connection settings between URI parameters and separate YAML keys until ownership becomes unclear.
databaseDefault database returned by GetMongoDBDatabase().Always.Default "test". All GetMongoDBCollection(name) calls resolve from this database.Forgetting to change the sample value and then creating collections in the wrong database.
usernameMongoDB auth username.Only for credential-based auth outside the URI.Default empty. The plugin only applies auth when both username and password are non-empty.Setting username alone and assuming auth was enabled.
passwordMongoDB auth password.Only for credential-based auth outside the URI.Default empty. Ignored unless username is also set.Populating a password but leaving username empty.
auth_sourceAuthentication database.Only with username and password.Default empty. Passed through with the credential block when auth is enabled.Setting auth_source without actually enabling username/password auth.
max_pool_sizeMaximum MongoDB driver pool size.Usually always.Default 100.Setting it too low for service concurrency and then blaming MongoDB for pool starvation.
min_pool_sizeMinimum MongoDB driver pool size.When you want some warm idle capacity.Default 5.Raising it for low-traffic services and paying for unused connections all day.
connect_timeoutInitial connection timeout.Usually always.Default "30s". Affects startup and reconnect attempts.Making it too small for cold starts or cross-zone connections.
server_selection_timeoutTime budget for selecting a MongoDB server.Especially important for replica sets and sharded clusters.Default "30s".Setting it too low during failover-prone or multi-node deployments.
socket_timeoutSocket read/write timeout.Usually always.Default "30s".Leaving it shorter than legitimate long-running MongoDB operations.
heartbeat_intervalDriver heartbeat interval.Usually leave the default.Default "10s". Lower values notice topology changes faster but create more background traffic.Tuning it down aggressively without checking cluster overhead.
enable_metricsTurns on plugin-local Prometheus metrics.When you will expose the plugin gatherer in /metrics.Default false.Enabling it but never merging GetMetricsGatherer() into the application's metrics endpoint.
enable_health_checkTurns on background health checks.When you want periodic runtime health visibility.Default false. Startup connection testing still happens either way.Setting it to false and assuming startup ping is disabled.
health_check_intervalBackground health-check interval.Only when enable_health_check: true.Default "30s".Tweaking it without enabling health checks and expecting any effect.
enable_tlsEnables TLS file handling for the client options.When the deployment requires TLS and you are using file-based TLS material.Default false. The implementation only builds a TLS config from the provided files; enable_tls: true with all TLS file paths empty does not inject a custom TLS config by itself.Setting enable_tls: true but providing neither TLS files nor URI-level TLS options.
tls_cert_fileClient certificate path.Only for mTLS-style setups with enable_tls: true.Default empty.Filling the path while leaving enable_tls off.
tls_key_fileClient private key path.Only for mTLS-style setups with enable_tls: true.Default empty.Setting a cert without its matching key.
tls_ca_fileCustom CA certificate path.When the cluster CA is not already trusted by the host.Default empty.Assuming a private CA will be trusted automatically.
enable_compressionEnables MongoDB compressor negotiation.When network savings matter and the cluster supports it.Default false. The plugin enables zlib and snappy.Setting compression_level alone and expecting compression to turn on.
compression_levelStored compression-level hint.Only as metadata for now.Default 0. The current implementation stores it but does not apply it to driver options.Tuning this field and expecting a runtime change today.
enable_retry_writesEnables retryable writes.When the cluster topology supports retryable writes.Default false.Enabling it against deployments that do not support retryable writes.
enable_read_concernApplies read concern to the client.When you need explicit read-consistency semantics.Default false.Setting read_concern_level and forgetting the enable flag.
read_concern_levelRead concern level.Only when enable_read_concern: true.Default "local". Unknown values fall back to local in the current implementation.Typos that silently degrade to local.
enable_write_concernApplies write concern to the client.When durability semantics matter.Default false.Setting write_concern_w / write_concern_timeout and forgetting this switch.
write_concern_wWrite concern acknowledgement level.Only when enable_write_concern: true.Default 1.Raising it without checking replica topology and latency impact.
write_concern_timeoutWrite concern timeout.Only when enable_write_concern: true.Default "5s".Setting a timeout shorter than normal replica acknowledgement latency.

Complete YAML Example

This example expands every field that appears in lynx-mongodb/conf/example_config.yml.

lynx:
mongodb:
uri: "mongodb://localhost:27017" # Base MongoDB connection URI.
database: "orders" # Default database returned by GetMongoDBDatabase().
username: "admin" # Credential username when you do not keep auth in the URI.
password: "change_me" # Credential password paired with username.
auth_source: "admin" # Authentication database for username/password auth.
max_pool_size: 100 # Maximum MongoDB driver pool size.
min_pool_size: 5 # Minimum warm idle connections kept by the driver.
connect_timeout: "30s" # Initial connection timeout.
server_selection_timeout: "30s" # Server-selection timeout for replica sets or sharded clusters.
socket_timeout: "30s" # Socket read/write timeout.
heartbeat_interval: "10s" # Driver heartbeat interval.
enable_metrics: true # Export plugin-local Prometheus metrics when you expose the gatherer.
enable_health_check: true # Run background health checks after startup.
health_check_interval: "30s" # Interval for background health checks.
enable_tls: false # Switch on TLS file handling when cert/key/CA files are provided.
tls_cert_file: "" # Optional client certificate path for mTLS.
tls_key_file: "" # Optional client private-key path for mTLS.
tls_ca_file: "" # Optional CA bundle path.
enable_compression: true # Enable zlib/snappy compressor negotiation.
compression_level: 6 # Stored compression-level hint; current runtime does not apply it to driver options.
enable_retry_writes: true # Enable retryable writes when topology supports them.
enable_read_concern: true # Apply read concern to the client.
read_concern_level: "local" # Read concern level used when enable_read_concern is true.
enable_write_concern: true # Apply write concern to the client.
write_concern_w: 1 # Write concern acknowledgement level.
write_concern_timeout: "5s" # Write concern timeout.

Minimum Viable YAML Example

The runtime can boot from defaults alone, so the smallest runnable block is an empty lynx.mongodb object.

lynx:
mongodb: {} # Defaults to mongodb://localhost:27017 and database "test" for local development.

Practical Notes

  • GetMongoDBCollection(name) resolves from the default database; collection creation, indexes, and document schema still belong to application code.
  • Metrics and background health checks are independent toggles: one controls observability export, the other controls periodic runtime probing.
  • If you prefer URI-native auth or TLS options, keep them in one place instead of mixing equivalent settings between the URI and top-level YAML.