mongo-base-crud (v0.4.4) is a TypeScript library that simplifies MongoDB CRUD operations with a class-based Singleton pattern, supporting multi-tenancy via dynamic database names and collection prefixes. It provides methods like save, update, partialUpdate, delete, find, findAll, getById, and aggregate. Key differentiators: built-in Singleton management (via getInstance or .instance()), automatic collection pluralization control, environment-based configuration, and full TypeScript type support. It requires Node.js >=14 and MongoDB >=4.x.
npm install mongo-base-crudNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage: getInstance to obtain a CRUD instance, save a document, and fetch it by ID.
Use .instance() with a unique alias per tenant or request context to avoid singleton conflicts.
Always validate or generate 'id' properly; consider using 'insertOne' from the underlying MongoDB driver for strict inserts.
Pass an object with 'id' key instead of a filter; e.g., { id: 'abc', name: 'new' }.Pass { disablePlural: true } in the config parameter of getInstance.Use import { BaseCrud } from 'mongo-base-crud'; then call BaseCrud.getInstance(...).Set "type": "module" in package.json, or use dynamic import() within a CommonJS file.
Run npm install typescript-singleton.