Blyp Docs

MongoDB

Use this path when your project stores Blyp logs in MongoDB through Mongoose.

This is database persistence, not connector forwarding. Blyp writes normalized database rows into a MongoDB collection when destination: "database" is enabled.

Prerequisites

Install

bun add mongoose

Config with a Mongoose instance

import mongoose from "mongoose";
import { createMongooseDatabaseAdapter } from "@blyp/core/database";

export default {
  destination: "database",
  database: {
    adapter: createMongooseDatabaseAdapter({
      mongoose,
      mongoUrl: process.env.MONGODB_URI,
      collection: "blyp_logs",
    }),
  },
};

Config with an existing connection

import mongoose from "mongoose";
import { createMongooseDatabaseAdapter } from "@blyp/core/database";

const connection = mongoose.connection;

export default {
  destination: "database",
  database: {
    adapter: createMongooseDatabaseAdapter({
      connection,
      collection: "blyp_logs",
    }),
  },
};

Config fields

The adapter config shape is:

type MongooseDatabaseAdapterConfig = {
  type: "mongoose";
  mongoose?: unknown;
  mongoUrl?: string;
  connection?: unknown;
  collection?: string;
};

createMongooseDatabaseAdapter and MongooseDatabaseAdapterConfig are exported from @blyp/core/database. The adapter is also available from the root @blyp/core package.

MongoDB does not require database.dialect: "postgres" | "mysql". That dialect field is only needed for SQL-backed Prisma and Drizzle setups.

Document shape

The MongoDB collection defaults to blyp_logs.

Blyp maps the internal row id to MongoDB _id. Other normalized log fields are stored on the document, including:

record contains the full normalized Blyp log payload. Keep it available when building queries or inspection tools around the collection.

Connection behavior

If connection is provided, Blyp uses it directly and expects the connection to expose a native MongoDB db instance.

If mongoose and mongoUrl are provided, Blyp connects before writing when the Mongoose connection is not already open.

If mongoose is already connected, Blyp reuses that connection.

If no usable Mongoose object or connection exists, database logging is disabled during config resolution or insert setup fails with a Blyp warning or error.

Delivery behavior

MongoDB uses the same database delivery settings as the other database adapters.

Default values:

Batch delivery also works with MongoDB:

import mongoose from "mongoose";
import { createMongooseDatabaseAdapter } from "@blyp/core/database";

export default {
  destination: "database",
  database: {
    adapter: createMongooseDatabaseAdapter({
      mongoose,
      mongoUrl: process.env.MONGODB_URI,
    }),
    delivery: {
      strategy: "batch",
      batchSize: 50,
      flushIntervalMs: 1000,
    },
  },
};