pluginagentmarketplace/custom-plugin-nodejs

mongoose-mongodb

Work with MongoDB in Node.js using Mongoose ODM for schema design, CRUD operations, relationships, and advanced queries

First seen Jan 22, 2026

Installation

$ npx skills add pluginagentmarketplace/custom-plugin-nodejs --skill mongoose-mongodb

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from pluginagentmarketplace/custom-plugin-nodejs · top by installs.

npx skills add pluginagentmarketplace/custom-plugin-nodejs

Browse all from pluginagentmarketplace/custom-plugin-nodejs

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Repository health

Stars 2
License LICENSE
Default branch main
Open issues 0
Status Active

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 4,982 B
  • docs SUMMARY.md 143 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 665 installs

SKILL.md

Mongoose & MongoDB Skill

Master MongoDB database integration in Node.js with Mongoose, the elegant object modeling library.

Quick Start

Connect and CRUD in 4 steps:

  1. Install - npm install mongoose
  2. Connect - mongoose.connect(uri)
  3. Define Schema - Create data models
  4. CRUD - Create, Read, Update, Delete

Core Concepts

Connection Setup

const mongoose = require('mongoose');

mongoose.connect(process.env.MONGODB_URI, {
  useNewUrlParser: true,
  useUnifiedTopology: true
});

mongoose.connection.on('connected', () => {
  console.log('MongoDB connected');
});

Schema & Model

const userSchema = new mongoose.Schema({
  name: {
    type: String,
    required: [true, 'Name is required'],
    trim: true,
    minlength: 3,
    maxlength: 50
  },
  email: {
    type: String,
    required: true,
    unique: true,
    lowercase: true
  },
  age: {
    type: Number,
    min: 18,
    max: 120
  },
  role: {
    type: String,
    enum: ['user', 'admin'],
    default: 'user'
  }
}, {
  timestamps: true  // createdAt, updatedAt
});

const User = mongoose.model('User', userSchema);

CRUD Operations

// Create
const user = await User.create({
  name: 'John Doe',
  email: '[email protected]'
});

// Read
const users = await User.find({ age: { $gte: 18 } });
const user = await User.findById(id);
const user = await User.findOne({ email: '[email protected]' });

// Update
const updated = await User.findByIdAndUpdate(
  id,
  { name: 'Jane Doe' },
  { new: true, runValidators: true }
);

// Delete
await User.findByIdAndDelete(id);
await User.deleteMany({ age: { $lt: 18 } });

Relationships & Population

const postSchema = new mongoose.Schema({
  title: String,
  content: String,
  author: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User'
  }
});

// Populate relationship
const post = await Post.findById(id).populate('author');
// post.author is now full user object

Learning Path

Beginner (2-3 weeks)

  • ✅ Install MongoDB and Mongoose
  • ✅ Create schemas and models
  • ✅ CRUD operations
  • ✅ Basic queries

Intermediate (4-5 weeks)

  • ✅ Relationships and population
  • ✅ Validation and middleware
  • ✅ Indexes for performance
  • ✅ Query operators

Advanced (6-8 weeks)

  • ✅ Aggregation pipelines
  • ✅ Transactions
  • ✅ Schema design patterns
  • ✅ Performance optimization

Advanced Features

Indexes

userSchema.index({ email: 1 }, { unique: true });
userSchema.index({ name: 1, age: -1 });

Middleware (Hooks)

userSchema.pre('save', async function(next) {
  if (this.isModified('password')) {
    this.password = await bcrypt.hash(this.password, 10);
  }
  next();
});

Virtual Properties

userSchema.virtual('fullName').get(function() {
  return `${this.firstName} ${this.lastName}`;
});

Aggregation Pipeline

const stats = await User.aggregate([
  { $match: { age: { $gte: 18 } } },
  { $group: {
    _id: '$role',
    count: { $sum: 1 },
    avgAge: { $avg: '$age' }
  }},
  { $sort: { count: -1 } }
]);

Query Operators

// Comparison
User.find({ age: { $gt: 18 } })     // Greater than
User.find({ age: { $gte: 18 } })    // Greater or equal
User.find({ age: { $lt: 65 } })     // Less than
User.find({ age: { $lte: 65 } })    // Less or equal
User.find({ age: { $ne: 30 } })     // Not equal

// Logical
User.find({ $and: [{ age: { $gte: 18 } }, { age: { $lte: 65 } }] })
User.find({ $or: [{ role: 'admin' }, { role: 'moderator' }] })

// Array
User.find({ tags: { $in: ['node', 'mongodb'] } })
User.find({ tags: { $nin: ['deprecated'] } })

// Regex
User.find({ email: /gmail\.com$/ })

Best Practices

  • ✅ Use environment variables for connection strings
  • ✅ Create indexes for frequently queried fields
  • ✅ Use lean() for read-only queries (better performance)
  • ✅ Validate data at schema level
  • ✅ Use transactions for multi-document operations
  • ✅ Handle connection errors properly
  • ✅ Close connections on app shutdown

When to Use

Use MongoDB with Mongoose when:

  • Building Node.js applications
  • Need flexible schema (document-based)
  • Handling large volumes of data
  • Rapid prototyping and iteration
  • Working with JSON-like data

Related Skills

  • Express REST API (connect to MongoDB)
  • Async Programming (async database operations)
  • JWT Authentication (store users)
  • Jest Testing (test database operations)

Resources