npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@maykonpaulo/maestro-provider-mongodb

v1.1.1

Published

MongoDB provider for @maykonpaulo/maestro-core — schema-inferred introspection (sampling), real CRUD, and missing-collection creation, per ADR 0007 (the first document/schema-less family provider).

Readme

@maykonpaulo/maestro-provider-mongodb

📖 Guia completo — criar o admin de qualquer sistema: está no README do pacote @maykonpaulo/maestro-server no npm → https://www.npmjs.com/package/@maykonpaulo/maestro-server

A MongoDB provider for @maykonpaulo/maestro-core — the first document/schema-less family provider, per ADR 0007 — Universal Provider Strategy. It implements all three of the core's provider contracts against a real MongoDB database:

  • IntrospectionProvider — discovers collections and infers each one's shape by sampling documents (there is no fixed schema to read). Every entity is reported with schemaless: true.
  • DatasourceProvider — real list/findById/create/update/delete/count, translated to native MongoDB queries (filters, sort, search, pagination).
  • SchemaWriteProviderensureEntity creates the collection if it does not exist yet (idempotent).

Why a separate package instead of a dialect of @maykonpaulo/maestro-provider-sql

MongoDB's query model (documents, no fixed columns, no information_schema) is genuinely different from the relational family — it cannot share the SQL query-building layer the relational dialects reuse. ADR 0007 groups providers by paradigm, not by exact product: this package is the whole document-store family for now, the way @maykonpaulo/maestro-provider-sql is the whole relational family.

Installation

npm install @maykonpaulo/maestro-provider-mongodb @maykonpaulo/maestro-core

@maykonpaulo/maestro-core and mongodb are peer dependencies — install the versions your project already uses.

Usage

import { runIntrospectionProvider } from '@maykonpaulo/maestro-core';
import { createMongoProvider } from '@maykonpaulo/maestro-provider-mongodb';

const provider = createMongoProvider({ uri: 'mongodb://localhost:27017', database: 'app' });

// Introspection — samples documents, validated/normalized via the core
const { result } = await runIntrospectionProvider(provider);

// Real CRUD against the same database
const created = await provider.create({ table: 'users', primaryKey: '_id', data: { name: 'Ada' } });
const page = await provider.list({ table: 'users', primaryKey: '_id', pagination: { strategy: 'page', page: 1, pageSize: 20 } });

// Create the collection if it isn't there yet
await provider.ensureEntity({ entity: { table: 'tags', fields: [] } });

Configuration

export interface MongoProviderOptions {
  uri?: string;              // a mongodb://... connection string
  client?: MongoClient;      // an already-connected client — for tests/embedding; caller owns its lifecycle
  database: string;          // required — Mongo has no "current database" to infer
  maxDocuments?: number;     // caps documents read per collection during introspection — unset by default (scans the whole collection)
}

Exactly one of uri or client must be provided.

_id handling

MongoDB always assigns a native ObjectId to _id unless the caller supplies one. This provider follows that default:

  • create() with primaryKey: '_id' and no _id in data lets Mongo generate a native ObjectId — the shape any pre-existing real collection almost certainly already uses. The returned record's _id is the ObjectId's string form.
  • findById/update/delete with primaryKey: '_id' accept a 24-hex-character id and match it against both a stored ObjectId and a stored plain string, so records created by this provider (which may hold either shape) and records that already existed in a real database (ObjectId) both resolve correctly.
  • A non-_id primary key (e.g. slug) is always treated as a plain value — Mongo has no special type for it. create() still generates a randomUUID() string when the caller doesn't supply one, matching every other provider in this monorepo.

What is introspected

Since there is no system catalog, introspection reads every document in every collection by default (maxDocuments is unset unless you explicitly cap it for a very large collection) and infers:

  • Fields — the union of keys observed across all scanned documents, each with the most-recently-seen non-null type.
  • Nullabilitytrue whenever a scanned document omitted the field or held null/undefined for it, or whenever fewer documents than were scanned actually carried the field.
  • Primary key_id is always marked isPrimaryKey: true.
  • schemaless: true on every entity (ADR 0007, DA-13) — signals to any consumer (CLI, declarative config generator, a future admin UI) that these fields are a likely shape, not a guarantee, unlike a relational provider's catalog-read columns. This is not about incomplete coverage of existing data — a full scan sees every document currently in the collection — it is an honest acknowledgment that MongoDB itself enforces no shape, so a document written a moment later can still introduce a field or type this result never saw. That is a property of the database, not a shortcut this provider takes.

What is not introspected (known limitations)

  • Relations — MongoDB has no foreign-key constraint to read. Guessing one from a field-naming convention (e.g. userId) would claim a confidence level ('definite'/'inferred') this provider cannot honestly back for a schemaless source, so relations is always [].
  • Indices — not introspected in this version.
  • Nested/embedded document shape — a field holding a sub-document is reported as a single 'json'-typed field; its inner structure is not recursively sampled.

Schema creation (ensureEntity)

Unlike a relational CREATE TABLE, a MongoDB collection carries no column definitions — entity.fields is not applied to the created collection, since there is nothing in Mongo's own model to apply it to. ensureEntity simply creates the (empty) collection if it doesn't already exist; the collection then accepts documents of whatever shape is written to it, per MongoDB's schemaless model.

Testing

Tests run against a real, ephemeral MongoDB server started per test run via mongodb-memory-server (downloads a real mongod binary once, then runs fully offline/in-process) — no Docker, no shared external database. See tests/mongo-provider.test.ts.

Turnkey admin (point at your database, get a UI)

This provider plugs straight into the Maestro turnkey layer: install @maykonpaulo/maestro-server and @maykonpaulo/maestro-admin, point them at your database and get a full governed admin (list/CRUD/RBAC/audit + a metadata-driven UI) with no per-entity code.

import { createMongoProvider } from '@maykonpaulo/maestro-provider-mongodb';
import { createMaestroServer, createIntrospectedEngine } from '@maykonpaulo/maestro-server';

const provider = createMongoProvider({ uri: 'mongodb://localhost:27017', database: 'app' });
const engine = await createIntrospectedEngine({ provider, access: 'full' });
await createMaestroServer({ engine }).listen(3000);

See the Turnkey admin guide.