Awesome-omni-skill Developing with MongoDB

The agent implements MongoDB NoSQL database solutions with document modeling, aggregation pipelines, and Mongoose ODM. Use when building document-based applications, designing schemas, writing aggregations, or implementing NoSQL patterns.

install
source · Clone the upstream repo
git clone https://github.com/diegosouzapw/awesome-omni-skill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/diegosouzapw/awesome-omni-skill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/development/developing-with-mongodb" ~/.claude/skills/diegosouzapw-awesome-omni-skill-developing-with-mongodb && rm -rf "$T"
manifest: skills/development/developing-with-mongodb/SKILL.md
source content

Developing with MongoDB

Quick Start

// Schema with Mongoose
import mongoose, { Schema, Document } from 'mongoose';

interface IUser extends Document {
  email: string;
  profile: { firstName: string; lastName: string };
  createdAt: Date;
}

const userSchema = new Schema<IUser>({
  email: { type: String, required: true, unique: true, lowercase: true },
  profile: {
    firstName: { type: String, required: true },
    lastName: { type: String, required: true },
  },
}, { timestamps: true });

userSchema.index({ email: 1 });
export const User = mongoose.model<IUser>('User', userSchema);

Features

FeatureDescriptionGuide
Document SchemaType-safe schema design with MongooseEmbed related data, use references for large collections
CRUD OperationsCreate, read, update, delete with type safetyUse
findById
,
findOne
,
updateOne
,
deleteOne
Aggregation PipelinesComplex data transformations and analyticsChain
$match
,
$group
,
$lookup
,
$project
stages
IndexingQuery optimization with proper indexesCreate compound indexes matching query patterns
TransactionsMulti-document ACID operationsUse sessions for operations requiring atomicity
Change StreamsReal-time data change notificationsWatch collections for inserts, updates, deletes

Common Patterns

Repository Pattern with Pagination

async findPaginated(filter: FilterQuery<IUser>, page = 1, limit = 20) {
  const [data, total] = await Promise.all([
    User.find(filter).sort({ createdAt: -1 }).skip((page - 1) * limit).limit(limit),
    User.countDocuments(filter),
  ]);
  return { data, pagination: { page, limit, total, totalPages: Math.ceil(total / limit) } };
}

Aggregation Pipeline

const stats = await Order.aggregate([
  { $match: { status: 'completed', createdAt: { $gte: startDate } } },
  { $group: { _id: '$userId', total: { $sum: '$amount' }, count: { $sum: 1 } } },
  { $sort: { total: -1 } },
  { $limit: 10 },
]);

Transaction for Order Creation

const session = await mongoose.startSession();
try {
  session.startTransaction();
  await Product.updateOne({ _id: productId }, { $inc: { stock: -quantity } }, { session });
  const order = await Order.create([{ userId, items, total }], { session });
  await session.commitTransaction();
  return order[0];
} catch (error) {
  await session.abortTransaction();
  throw error;
} finally {
  session.endSession();
}

Best Practices

DoAvoid
Design schemas based on query patternsEmbedding large arrays in documents
Create indexes for frequently queried fieldsUsing
$where
or mapReduce in production
Use
lean()
for read-only queries
Skipping validation on writes
Implement pagination for large datasetsStoring large files directly (use GridFS)
Set connection pool size appropriatelyHardcoding connection strings
Use transactions for multi-document opsIgnoring index usage in explain plans
Add TTL indexes for expiring dataCreating too many indexes (write overhead)