Database Support
MongoDB
errorcore instruments the official mongodb driver when IO recording is active. Operations are recorded with their collection target, operation type, and duration.
Setup
Initialize errorcore before connecting your MongoDB client:
import errorcore from "errorcore";
errorcore.init({
service: "catalog-api",
transport: { type: "file", path: "./errors.ndjson" },
allowUnencrypted: true,
});
// connect after init()
import { MongoClient } from "mongodb";
const client = new MongoClient(process.env.MONGO_URI);
await client.connect();
const db = client.db("catalog");What gets recorded
Each operation in the IO timeline includes:
- operation type (
find,insertOne,updateMany,deleteOne, etc.) - collection name
- duration in milliseconds
- position in the ordered timeline
5ms find on products
11ms findOne on inventory
16ms updateOne on inventory
20ms Error thrown: out of stockFilter and document capture
Full filter objects and documents are not included in the timeline by default. They often contain user-specific data and can inflate the package size significantly.
If you need query filters for debugging specific failure paths, use the piiScrubber to control what reaches the package:
errorcore.init({
service: "catalog-api",
transport: { type: "file", path: "./errors.ndjson" },
encryptionKey: process.env.ERRORCORE_KEY,
piiScrubber: (key, value) => {
if (key === "params" && typeof value === "string") {
try {
const parsed = JSON.parse(value);
// keep only the query shape, strip values
const keys = Object.keys(parsed);
return JSON.stringify(Object.fromEntries(keys.map(k => [k, "[filtered]"])));
} catch {
return "[filtered]";
}
}
return value;
},
});Stick to operation names and collection targets for most workloads. That is usually enough to identify the failing path without leaking document contents.