( PRODUCT LANDING )Query Observability Wedge

Find slow MongoDB queries inside your API traces

Standard query loggers tell you a query is slow, but they lack execution path context. TraceMole connects your API request flow directly to MongoDB explain metrics, showing exactly which endpoint runs COLLSCAN pipelines.

Key Capabilities

API Trace Correlation

Automatically tags query metrics with OpenTelemetry span parents. Trace DB bottlenecks directly to their originating HTTP paths and request context.

Explain Statistics Audit

Captures scan ratios (documents examined vs documents returned) and alerts you immediately when an unindexed COLLSCAN takes place in production.

Why MongoDB queries become slow

MongoDB queries typically degrade in performance due to missing or inefficient indexes. When the database engine has to perform a collection scan (COLLSCAN) instead of an index scan (IXSCAN), it reads every document in the collection. As your database grows to millions of rows, linear scans exhaust CPU resources and cause severe API bottlenecks.

Track docsExamined vs nReturned

A key indicator of query efficiency is the ratio between the number of documents examined (docsExamined) and the number of documents actually returned (nReturned). In an optimal query, this ratio is 1:1. When the database scans thousands of documents just to return a handful, it is a sign that your compound index lacks the necessary prefix fields.

Quick Integration

TraceMole wraps standard MongoDB drivers with zero performance penalties. telemetries are captured asynchronously.

// Setup MongoClient with command monitoring and register query explain listener
import { MongoClient } from "mongodb";
import { registerTraceMoleListener } from "@tracemole/nextjs-mongodb-explain";

const client = new MongoClient(process.env.MONGO_DB_URL, { monitorCommands: true });
registerTraceMoleListener(client, { slowThreshold: 0 });
export const db = client.db("app_database");
Data Privacy Principle

We only collect query patterns and execution stats. Your raw collection records and transaction payloads never leave your network boundary.