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

@digitaldefiance/node-express-suite-mongo

v4.23.3

Published

MongoDB/Mongoose extensions for @digitaldefiance/node-express-suite

Readme

@digitaldefiance/node-express-suite-mongo

License: MIT

MongoDB/Mongoose extensions for @digitaldefiance/node-express-suite.

This package provides the Mongoose-specific layer — documents, schemas, models, services, and plugins — that was originally part of @digitaldefiance/node-express-suite. If your application uses MongoDB, install this package alongside the base package.

Part of Express Suite.

Installation

npm install @digitaldefiance/node-express-suite @digitaldefiance/node-express-suite-mongo
# or
yarn add @digitaldefiance/node-express-suite @digitaldefiance/node-express-suite-mongo

Peer Dependencies

  • @digitaldefiance/node-express-suite (base framework)
  • mongodb
  • mongoose (via @digitaldefiance/mongoose-types)

What's in This Package

Everything MongoDB/Mongoose-specific that was extracted from the base package:

| Category | Contents | |----------|----------| | Documents | BaseDocument, UserDocument, RoleDocument, EmailTokenDocument, MnemonicDocument, UserRoleDocument, UsedDirectLoginTokenDocument | | Schemas | UserSchema, RoleSchema, EmailTokenSchema, MnemonicSchema, UserRoleSchema, UsedDirectLoginTokenSchema, and create*Schema factory functions | | Models | Model factory functions for all document types | | Services | UserService, RoleService, BackupCodeService, DatabaseInitializationService, MongoBaseService, MongoAuthenticationProvider, MongooseDatabase, MongooseCollection, MongooseDocumentStore, MongooseSessionAdapter, DirectLoginTokenService, MnemonicService, RequestUserService | | Controllers | UserController, MongoBaseController | | Plugins | MongoDatabasePlugin | | Transactions | TransactionManager, withTransaction (Mongoose Connection overload) | | Interfaces | IMongoApplication, IMongoEnvironment, IMongoTypedEnvironment, ISchema, IMongoErrors, IApiMongoValidationErrorResponse, and more | | Enumerations | BaseModelName, SchemaCollection | | Errors | MongooseValidationError, ModelNotRegisteredError, InvalidModelError | | Types | MongoTransactionCallback, SchemaMap, Mongoose helper types | | Utilities | ModelRegistry, MongoApplicationConcrete, defaultMongoUriValidator, isValidStringObjectId, sendApiMongoValidationErrorResponse | | Routers | ApiRouter (Mongo-aware API router with UserController) |

Quick Start

import { Application, emailServiceRegistry, DummyEmailService } from '@digitaldefiance/node-express-suite';
import {
  MongoDatabasePlugin,
  DatabaseInitializationService,
  ApiRouter,
  getSchemaMap,
} from '@digitaldefiance/node-express-suite-mongo';

// Create your application
const env = new Environment(join(__dirname, '.env'));
const app = new Application(env, /* ... */);

// Set up the MongoDatabasePlugin
const mongoPlugin = new MongoDatabasePlugin({
  schemaMapFactory: getSchemaMap,
  databaseInitFunction: DatabaseInitializationService.initUserDb,
  initResultHashFunction: DatabaseInitializationService.serverInitResultHash,
  environment: env,
  constants: myConstants,
});
app.useDatabasePlugin(mongoPlugin);

// Register email service
emailServiceRegistry.setService(new DummyEmailService(app));

await app.start();

MongoDatabasePlugin

The plugin manages the full Mongoose lifecycle: connection, schema registration, model creation, and database initialization.

const plugin = new MongoDatabasePlugin({
  schemaMapFactory: getSchemaMap,       // Returns your SchemaMap
  databaseInitFunction: initFn,         // Called after connection to seed data
  initResultHashFunction: hashFn,       // Hashes init results for change detection
  environment: env,                     // Must include env.mongo config
  constants: myConstants,
});

// The plugin exposes:
plugin.db;                  // Mongoose connection
plugin.mongoApplication;    // IMongoApplication adapter
plugin.authenticationProvider; // MongoAuthenticationProvider

ModelRegistry

A singleton registry for Mongoose models, allowing any service to look up models by name:

import { ModelRegistry, BaseModelName } from '@digitaldefiance/node-express-suite-mongo';

// Retrieve a typed model
const UserModel = ModelRegistry.instance.getTypedModel<UserDocument>(BaseModelName.User);
const user = await UserModel.findById(userId);

Extending Schemas

Clone and extend base schemas for your application:

import { createUserSchema } from '@digitaldefiance/node-express-suite-mongo';

const BaseUserSchema = createUserSchema(undefined, undefined, undefined, undefined, undefined, undefined, myConstants);
const MyUserSchema = BaseUserSchema.clone();
MyUserSchema.add({
  organizationId: { type: String, required: true },
});

DatabaseInitializationService

Seeds the database with default admin/member users, roles, and system configuration:

import { DatabaseInitializationService } from '@digitaldefiance/node-express-suite-mongo';

const result = await DatabaseInitializationService.initUserDb(mongoApp);
if (result.success) {
  console.log('Admin mnemonic:', result.data.adminMnemonic);
}

Convenience Re-exports

For simpler imports, this package re-exports key symbols from the base package:

  • Application, BaseController, DecoratorBaseController, BaseService, AppRouter, BaseRouter
  • IApplication, IConstants, IAuthenticationProvider, IDatabasePlugin, IEnvironment

Migration from Pre-Split Versions

If upgrading from @digitaldefiance/node-express-suite < 5.0 (before the split):

  1. Install this package alongside the base package
  2. Update imports: move Mongo-specific symbols to @digitaldefiance/node-express-suite-mongo
  3. Symbols that stay in the base package: Application, BaseController, BaseService, Environment, AppRouter, BaseRouter, decorators, middleware, utilities, i18n, validation, responses, builders
  4. Symbols that move here: documents, schemas, models, MongoDatabasePlugin, DatabaseInitializationService, UserService, RoleService, BackupCodeService, UserController, ModelRegistry, TransactionManager, ApiRouter, all Mongoose-specific interfaces/types/errors

License

MIT