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

@shadow-library/mongoose

v0.0.4

Published

A modular Mongoose integration for the Shadow framework, enabling schema definitions, connections, and model injection using decorators.

Readme

@shadow-library/mongoose

@shadow-library/mongoose is a MongoDB integration module for the Shadow application framework. Inspired by @nestjs/mongoose, it provides a seamless and structured way to define schemas, connect to databases, and inject Mongoose models into your application using decorators and a module-based architecture.

✨ Features

  • Connect to MongoDB using a declarative, modular API
  • Define Mongoose schemas using class decorators
  • Inject models via dependency injection
  • Supports multiple connections and async configuration
  • Follows the architectural conventions of the Shadow framework

📦 Installation

# npm
npm install @shadow-library/mongoose mongoose

# Yarn
yarn add @shadow-library/mongoose mongoose

# pnpm
pnpm add @shadow-library/mongoose mongoose

# bun
bun add @shadow-library/mongoose mongoose

🚀 Getting Started

1. Register the Mongoose Module

import { Module } from '@shadow-library/app';
import { MongooseModule } from '@shadow-library/mongoose';

@Module({
  imports: [MongooseModule.forRoot('mongodb://localhost/shadow-db')],
})
export class AppModule {}

2. Define a Schema with Decorators

import { Schema, Prop, SchemaFactory } from '@shadow-library/mongoose';

@Schema()
export class User {
  @Prop({
    type: String,
    required: true,
  })
  name: string;

  @Prop({
    type: String,
    unique: true,
  })
  email: string;

  @Prop({
    type: Number,
  })
  age: number;
}

export const UserSchema = SchemaFactory.createForClass(User);

3. Register the Feature Model

import { Module } from '@shadow-library/app';
import { MongooseModule } from '@shadow-library/mongoose';
import { User, UserSchema } from './user.schema';
import { UserService } from './user.service';

@Module({
  imports: [MongooseModule.forFeature([{ name: User.name, schema: UserSchema }])],
  providers: [UserService],
})
export class UserModule {}

4. Inject and Use the Model

import { Injectable } from '@shadow-library/app';
import { InjectModel } from '@shadow-library/mongoose';
import { Model } from 'mongoose';
import { User } from './user.schema';

@Injectable()
export class UserService {
  constructor(@InjectModel(User.name) private readonly userModel: Model<User>) {}

  async create(data: Partial<User>) {
    return this.userModel.create(data);
  }

  async findAll() {
    return this.userModel.find().exec();
  }
}

🧩 Advanced Configuration

Async Initialization

MongooseModule.forRootAsync({
  useFactory: async () => ({
    uri: process.env.MONGO_URI,
    dbName: 'custom-db',
  }),
});

Multiple Connections

MongooseModule.forRoot('mongodb://localhost/db1', { connectionName: 'db1' }),
MongooseModule.forRoot('mongodb://localhost/db2', { connectionName: 'db2' }),

And register models per connection:

MongooseModule.forFeature(
  [{ name: User.name, schema: UserSchema }],
  'db1',
),

📖 API Reference

  • MongooseModule.forRoot(uri, options?) – Register a global connection
  • MongooseModule.forRootAsync(options) – Register connection asynchronously
  • MongooseModule.forFeature(models, connectionName?) – Register feature models
  • @Schema() – Decorate a class as a Mongoose schema
  • @Prop(options) – Decorate properties as schema fields
  • SchemaFactory.createForClass(Class) – Create schema from class
  • @InjectModel(name, connectionName?) – Inject a Mongoose model

🛠 Requirements

  • Node.js v22+
  • Mongoose v8+
  • Shadow application framework (based on @shadow-library/app)

📝 License

MIT


Built with ❤️ for the Shadow application ecosystem.