$ miric.dev

Open Source

MongoDB Datasource

Open-source MongoDB plugin for Grafana

01

The Gap

Grafana’s official MongoDB plugin requires an Enterprise license. The most established community alternative never shipped a stable release. If you run MongoDB in production and want Grafana dashboards without an Enterprise contract, your options have been limited.

This plugin fills that gap — a production-quality, open-source datasource with a Go backend for secure, high-performance MongoDB communication and first-class support for aggregation pipelines, template variables, and BSON types.

02

Architecture

The plugin follows a three-tier design. A React/TypeScript frontend handles the configuration and query editors. A Go backend manages MongoDB connections, executes aggregation pipelines, and converts BSON results into Grafana DataFrames. The two communicate via gRPC through Grafana’s DataSourceWithBackend proxy.

Grafana Frontend

React / TypeScript

Config EditorQuery EditorData Hooks

Go Backend Plugin

gRPC

Connection PoolPipeline ExecutionBSON → DataFrame

MongoDB

mongo-driver/v2

Aggregation PipelinesAtlas SRVTLS / X.509

03

Macros & Variables

Raw aggregation pipelines give you full control, but repeating time range logic and variable substitution across every panel gets tedious. The plugin ships with five built-in macros and 15+ template variables that handle the boilerplate.

MacroDescription
$__timeFilter(field)Scopes documents to the dashboard time range
$__timeGroup(field)Buckets documents into time intervals
$__oidFilter(field)Filters by ObjectID-encoded timestamps
$__timeFilter_ms(field)Time filter for millisecond-precision fields
$__matchIndex-friendly multi-select with smart "All" handling

Time-series query with macros

[
  { "$match": { "$__timeFilter": "timestamp" } },
  { "$sort": { "timestamp": 1 } },
  { "$project": { "_id": 0, "timestamp": 1, "value": 1, "location": 1 } }
]

04

Full BSON Support

MongoDB documents use BSON types that most Grafana plugins struggle with. This plugin converts the full spectrum — ObjectID, Decimal128, Date, nested documents, arrays — into Grafana-native DataFrame fields. No more broken panels from unrecognised types.

Both time-series and table output formats are supported. The Go backend handles type detection and conversion automatically, so you write standard aggregation pipelines without worrying about serialisation edge cases.

ObjectID
Decimal128
Date
Int32 / Int64
Double
String
Boolean
Array
Embedded Doc
Binary
Null
Timestamp

05

Getting Started

Install via the Grafana CLI, drop in a release archive, or spin up the Docker Compose environment to try it locally with pre-loaded sample data and a configured dashboard.

Install via Grafana CLI

grafana-cli plugins install milosmiric-mongodb-datasource

Or try locally with Docker

docker compose up
# Open http://localhost:3105 (admin/admin)

Supports standard MongoDB connection URIs with SCRAM-SHA-256, SCRAM-SHA-1, X.509 authentication, TLS/SSL, and Atlas SRV connections out of the box.