This repository contains runnable examples for the Atlas Go SDK that align with best practices from the MongoDB Atlas Architecture Center.
Use these examples as starting points for your own Atlas integration.
Currently, the repository includes examples that demonstrate the following:
- Authenticate with service accounts
- Return cluster and database metrics
- Download logs for a specific host
- Pull and parse line-item-level billing data
- Return all linked organizations from a specific billing organization
- Get historical invoices for an organization
As the Architecture Center documentation evolves, this repository will be updated with new examples and improvements to existing code.
.
├── examples # Runnable examples by category
│ ├── billing/
│ └── monitoring/
├── configs # Atlas configuration templates & environment-specific configs
│ └── config.example.json
├── internal # Shared utilities and helpers
│ ├── auth/
│ ├── billing/
│ ├── clusterutils/
│ ├── config/
│ ├── data/
│ ├── errors/
│ ├── fileutils/
│ ├── logs/
│ ├── metrics/
│ └── orgutils/
├── go.mod
├── go.sum
├── CHANGELOG.md # List of major changes to the project
├── .gitignore # Ignores .env file and log output
└── .env.example # Example environment variables
- Go 1.24 or later
- A MongoDB Atlas organization, project, and at least one cluster
- Service account credentials with appropriate permissions and IP access. See Service Account Overview
Create a .env.<environment> file (e.g. .env.development):
# Required service account credentials
MONGODB_ATLAS_SERVICE_ACCOUNT_ID=<your_service_account_id>
MONGODB_ATLAS_SERVICE_ACCOUNT_SECRET=<your_service_account_secret>
# Optional: override default config path (defaults to configs/config.json if unset)
CONFIG_PATH=configs/config.development.json
# Optional: base directory for downloaded artifacts (logs, archives, invoices)
ATLAS_DOWNLOADS_DIR=tmp/atlas_downloadsNOTE: For production, store secrets in a secrets manager (e.g. HashiCorp Vault, AWS Secrets Manager) instead of plain environment variables. See Secrets management.
Create configs/config.<environment>.json (e.g. configs/config.development.json).
If CONFIG_PATH is unset, the loader falls back to configs/config.json.
Minimal example:
{
"ATLAS_ORG_ID": "<your-org-id>",
"ATLAS_PROJECT_ID": "<your-project-id>",
"ATLAS_CLUSTER_NAME": "<a-cluster-name>",
"ATLAS_PROCESS_ID": "<cluster-hostname:port>"
}ATLAS_PROCESS_ID: used for examples that operate directly on a single host (logs/metrics). Format:hostname:port.
Each example is an independent entrypoint. Ensure your .env.<env> and matching config file are in place, then:
# Example: run with development environment
cp .env.example .env.development # (or create manually)
# edit .env.development and config file with real values
# Billing - historical invoices
go run examples/billing/historical/main.go
# Billing - line items
go run examples/billing/line_items/main.go
# Billing - linked organizations
go run examples/billing/linked_orgs/main.go
# Logs - fetch host logs
go run examples/monitoring/logs/main.go
# Metrics - disk measurements
go run examples/monitoring/metrics_disk/main.go
# Metrics - process CPU metrics
go run examples/monitoring/metrics_process/main.goFor a list of major changes to this project, see CHANGELOG.
Use the "Rate this page" widget on the Atlas Architecture Center docs to leave feedback or file issues.
This project is licensed under Apache 2.0. See LICENSE.
