
Mongodb
- 21 installs
- 1 repo stars
- Updated January 5, 2026
- pluginagentmarketplace/custom-plugin-sql
mongodb is a Claude Code skill for ai & agent building.
About
mongodb is a Claude Code skill for ai & agent building. It helps solo builders move faster with AI-assisted development.
- mongodb
- AI & Agent Building
- AI-coding skill
Mongodb by the numbers
- 21 all-time installs (skills.sh)
- Ranked #10,289 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-sql --skill mongodbAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 21 |
|---|---|
| repo stars | ★ 1 |
| Last updated | January 5, 2026 |
| Repository | pluginagentmarketplace/custom-plugin-sql ↗ |
How do I helps with ai & agent building tasks.?
Helps with ai & agent building tasks.
Who is it for?
Best when you're working on ai & agent building and need structured help with mongodb.
Skip if: Teams with no ai & agent building needs, or anyone wanting a generic chat assistant without this specific workflow.
When should I use this skill?
When you need to helps with ai & agent building tasks., or when mongodb is a claude code skill for ai & agent building.
What you get
Structured output aligned to mongodb: mongodb, AI & Agent Building.
Files
MongoDB Mastery
Document Model Basics
// MongoDB document (JSON-like structure)
{
_id: ObjectId("507f1f77bcf86cd799439011"),
firstName: "John",
lastName: "Doe",
email: "john@example.com",
salary: 75000,
department: "Engineering",
skills: ["JavaScript", "Python", "SQL"],
address: {
street: "123 Main St",
city: "New York",
state: "NY"
},
joinDate: new Date("2023-01-15")
}Collection Operations
// Create database and collection
use company_db
// Insert single document
db.employees.insertOne({
firstName: "Jane",
lastName: "Smith",
email: "jane@example.com",
salary: 80000
})
// Insert multiple documents
db.employees.insertMany([
{ firstName: "Bob", lastName: "Johnson", salary: 70000 },
{ firstName: "Alice", lastName: "Williams", salary: 85000 }
])
// Get document count
db.employees.countDocuments({})
// Validate collection
db.employees.validate()CRUD Operations
// READ - Basic find
db.employees.find()
// Find by condition
db.employees.find({ salary: { $gt: 75000 } })
// Find with projection (select specific fields)
db.employees.find(
{ department: "Engineering" },
{ firstName: 1, lastName: 1, salary: 1, _id: 0 }
)
// Find one document
db.employees.findOne({ email: "john@example.com" })
// UPDATE - Update one document
db.employees.updateOne(
{ _id: ObjectId("...") },
{ $set: { salary: 90000 } }
)
// Update multiple documents
db.employees.updateMany(
{ department: "Engineering" },
{ $set: { bonus: 5000 } }
)
// DELETE - Delete documents
db.employees.deleteOne({ _id: ObjectId("...") })
db.employees.deleteMany({ department: "HR" })Query Operators
// Comparison operators
db.employees.find({ salary: { $gt: 75000 } }) // Greater than
db.employees.find({ salary: { $gte: 75000 } }) // Greater than or equal
db.employees.find({ salary: { $lt: 75000 } }) // Less than
db.employees.find({ salary: { $lte: 75000 } }) // Less than or equal
db.employees.find({ salary: { $eq: 75000 } }) // Equal
db.employees.find({ salary: { $ne: 75000 } }) // Not equal
// Array operators
db.employees.find({ skills: "JavaScript" }) // Contains value
db.employees.find({ skills: { $in: ["Python", "Go"] } }) // Contains any
db.employees.find({ skills: { $all: ["JavaScript", "Python"] } }) // Contains all
db.employees.find({ skills: { $size: 3 } }) // Array size
// Element operators
db.employees.find({ phone: { $exists: true } }) // Field exists
db.employees.find({ salary: { $type: "number" } }) // Field type check
// String matching
db.employees.find({ email: { $regex: "gmail" } }) // Regular expressionSorting and Limiting
// Sort by single field
db.employees.find().sort({ salary: -1 }) // Descending
db.employees.find().sort({ salary: 1 }) // Ascending
// Sort by multiple fields
db.employees.find().sort({ department: 1, salary: -1 })
// Limit and skip
db.employees.find().limit(10) // First 10 results
db.employees.find().skip(20).limit(10) // PaginationIndexing
// Create single field index
db.employees.createIndex({ email: 1 })
// Create unique index
db.employees.createIndex({ email: 1 }, { unique: true })
// Create compound index
db.employees.createIndex({ department: 1, salary: -1 })
// Create text index for search
db.employees.createIndex({ firstName: "text", lastName: "text" })
// List indexes
db.employees.getIndexes()
// Drop index
db.employees.dropIndex("email_1")
// Full text search with text index
db.employees.find({ $text: { $search: "john" } })Data Types
// String
{ name: "John Doe" }
// Number (Int32, Int64, Double)
{ age: 30, salary: 75000.50 }
// Boolean
{ active: true }
// Date
{ createdDate: new Date() }
// Array
{ skills: ["JavaScript", "Python"] }
// Object/Embedded document
{ address: { city: "NYC", state: "NY" } }
// ObjectID
{ _id: ObjectId() }
// Null
{ phone: null }
// Regular Expression
{ email: /gmail/ }Bulk Operations
// Initialize bulk operation
let bulk = db.employees.initializeUnorderedBulkOp()
// Add multiple operations
bulk.find({ department: "Engineering" }).update({ $set: { bonus: 5000 } })
bulk.find({ salary: { $lt: 50000 } }).update({ $inc: { salary: 2000 } })
bulk.insert({ firstName: "New", lastName: "Employee" })
bulk.find({ _id: ObjectId("...") }).removeOne()
// Execute bulk
bulk.execute()Aggregation Pipeline (Data Processing)
// Basic pipeline stages
db.employees.aggregate([
{ $match: { salary: { $gt: 75000 } } }, // Filter
{ $group: { // Group & aggregate
_id: "$department",
avgSalary: { $avg: "$salary" },
count: { $sum: 1 }
}},
{ $sort: { avgSalary: -1 } }, // Sort
{ $limit: 5 } // Limit results
])
// Projection stage (reshape documents)
db.employees.aggregate([
{ $project: {
fullName: { $concat: ["$firstName", " ", "$lastName"] },
salary: 1,
yearing_salary: { $multiply: ["$salary", 12] },
_id: 0
}}
])
// Unwind arrays for analysis
db.employees.aggregate([
{ $unwind: "$skills" }, // Expand skills array
{ $group: {
_id: "$skills",
count: { $sum: 1 }
}},
{ $sort: { count: -1 } }
])
// Lookup (similar to SQL JOIN)
db.orders.aggregate([
{ $lookup: {
from: "customers",
localField: "customerId",
foreignField: "_id",
as: "customerInfo"
}},
{ $unwind: "$customerInfo" },
{ $project: {
orderId: 1,
"customerInfo.name": 1,
"customerInfo.email": 1,
amount: 1
}}
])
// Complex multi-stage pipeline
db.sales.aggregate([
{ $match: { date: { $gte: new Date("2023-01-01") } } },
{ $group: {
_id: { month: { $month: "$date" }, year: { $year: "$date" } },
totalSales: { $sum: "$amount" },
avgSale: { $avg: "$amount" },
ordersCount: { $sum: 1 }
}},
{ $sort: { "_id.year": 1, "_id.month": 1 } },
{ $project: {
month: "$_id.month",
year: "$_id.year",
totalSales: { $round: ["$totalSales", 2] },
avgSale: { $round: ["$avgSale", 2] },
ordersCount: 1,
_id: 0
}}
])Transactions (ACID)
// Start a session
const session = db.getMongo().startSession()
session.startTransaction()
try {
// Multiple operations in transaction
db.accounts.updateOne(
{ _id: "account1" },
{ $inc: { balance: -100 } },
{ session: session }
)
db.accounts.updateOne(
{ _id: "account2" },
{ $inc: { balance: 100 } },
{ session: session }
)
// All succeed or all fail
session.commitTransaction()
} catch (error) {
session.abortTransaction()
throw error
} finally {
session.endSession()
}Update Operators
// $set - set field value
db.employees.updateOne(
{ _id: ObjectId("...") },
{ $set: { salary: 90000 } }
)
// $inc - increment field
db.employees.updateOne(
{ _id: ObjectId("...") },
{ $inc: { salary: 5000 } }
)
// $push - add to array
db.employees.updateOne(
{ _id: ObjectId("...") },
{ $push: { skills: "Kubernetes" } }
)
// $addToSet - add to array if not exists
db.employees.updateOne(
{ _id: ObjectId("...") },
{ $addToSet: { skills: "Docker" } }
)
// $pull - remove from array
db.employees.updateOne(
{ _id: ObjectId("...") },
{ $pull: { skills: "COBOL" } }
)
// $unset - remove field
db.employees.updateOne(
{ _id: ObjectId("...") },
{ $unset: { phone: "" } }
)
// Combination updates
db.employees.updateOne(
{ _id: ObjectId("...") },
{
$set: { updatedAt: new Date() },
$inc: { salary: 5000 },
$push: { performanceRatings: 4.5 }
}
)Array Queries
// Query array elements
db.employees.find({ skills: "Python" }) // Has Python skill
// Query array with conditions
db.employees.find({
skills: { $elemMatch: { $eq: "JavaScript" } }
})
// Array position operators
db.orders.updateOne(
{ _id: ObjectId("..."), "items.sku": "SKU123" },
{ $set: { "items.$.quantity": 5 } } // Update matching item
)
// Multiple array criteria
db.orders.find({
items: { $elemMatch: {
sku: "SKU123",
quantity: { $gt: 3 }
}}
})Real-World Examples
E-commerce Product Catalog
db.products.insertOne({
_id: ObjectId(),
sku: "PROD-001",
name: "Laptop",
price: 999.99,
stock: 50,
categories: ["Electronics", "Computers"],
specs: {
cpu: "Intel i7",
ram: "16GB",
storage: "512GB SSD"
},
reviews: [
{ userId: "user1", rating: 5, comment: "Great!" },
{ userId: "user2", rating: 4, comment: "Good value" }
],
lastUpdated: new Date()
})
// Update stock with transaction
session.startTransaction()
db.products.updateOne({ sku: "PROD-001" }, { $inc: { stock: -1 } }, { session })
db.orders.insertOne({ productId: ObjectId(), quantity: 1 }, { session })
session.commitTransaction()User Profiles with Flexible Schema
db.users.insertOne({
_id: ObjectId(),
username: "john_doe",
email: "john@example.com",
profile: {
firstName: "John",
lastName: "Doe",
bio: "Software engineer",
socialLinks: {
github: "john-doe",
twitter: "@johndoe"
}
},
preferences: {
theme: "dark",
notifications: true,
language: "en"
},
metadata: {
createdAt: new Date(),
lastLogin: new Date(),
loginCount: 42
}
})
// Flexible update - can add new fields
db.users.updateOne(
{ username: "john_doe" },
{ $set: { "profile.avatar": "url", "preferences.emailFrequency": "weekly" } }
)Performance Tips
// Create indexes for common queries
db.employees.createIndex({ email: 1 })
db.employees.createIndex({ department: 1, salary: -1 })
// Use explain to optimize queries
db.employees.find({ salary: { $gt: 75000 } }).explain("executionStats")
// Projection to reduce data transfer
db.employees.find(
{ salary: { $gt: 75000 } },
{ firstName: 1, lastName: 1, salary: 1, _id: 0 }
)
// Batch writes for bulk inserts
db.employees.insertMany(largeArray, { ordered: false })
// Aggregation optimization (match early)
db.orders.aggregate([
{ $match: { status: "completed" } }, // Early filter
{ $lookup: { from: "customers", ... } },
{ $group: { _id: "$customerId", total: { $sum: "$amount" } } }
])Next Steps
Learn NoSQL design patterns, denormalization strategies, and advanced schema design in the nosql-design skill.
sql_skill: mongodb
NoSQL Design Patterns
Embedding vs Referencing
Embedding Pattern (Denormalization)
// One-to-one: Embed related data
db.employees.findOne()
{
_id: ObjectId("..."),
firstName: "John",
lastName: "Doe",
address: {
street: "123 Main St",
city: "New York",
state: "NY",
zip: "10001"
},
contact: {
email: "john@example.com",
phone: "555-1234"
}
}
// One-to-few: Embed small arrays
db.employees.findOne()
{
_id: ObjectId("..."),
firstName: "John",
skills: ["JavaScript", "Python", "SQL"],
certifications: [
{ name: "AWS Solutions Architect", year: 2023 },
{ name: "Google Cloud Professional", year: 2022 }
]
}Referencing Pattern (Normalization)
// One-to-many: Reference related documents
// employees collection
{
_id: ObjectId("emp1"),
firstName: "John",
lastName: "Doe",
department_id: ObjectId("dept1")
}
// departments collection
{
_id: ObjectId("dept1"),
name: "Engineering",
budget: 500000
}
// Query with $lookup (join)
db.employees.aggregate([
{
$lookup: {
from: "departments",
localField: "department_id",
foreignField: "_id",
as: "department"
}
},
{ $unwind: "$department" }
])Common Schema Patterns
Polymorphic Pattern
// Handle different document types in same collection
db.items.find()
[
{
type: "book",
title: "MongoDB Guide",
author: "John Doe",
isbn: "123-456"
},
{
type: "course",
title: "MongoDB Mastery",
instructor: "Jane Smith",
duration: 40,
language: "English"
},
{
type: "video",
title: "MongoDB Basics",
channel: "Tech Channel",
duration_minutes: 45,
url: "https://..."
}
]
// Query by type
db.items.find({ type: "book" })Attribute Pattern
// Flexible attribute storage for varying data
{
_id: ObjectId("prod1"),
name: "Laptop",
category: "Electronics",
attributes: [
{ key: "RAM", value: "16GB" },
{ key: "Storage", value: "512GB SSD" },
{ key: "Processor", value: "Intel i7" },
{ key: "Screen", value: "15.6 inch" }
]
}
// Query attributes
db.products.find({ "attributes.key": "RAM", "attributes.value": "16GB" })Extended Reference Pattern
// Store frequently accessed data to avoid lookups
// Users collection with department info cached
{
_id: ObjectId("user1"),
firstName: "John",
department_id: ObjectId("dept1"),
department_name: "Engineering", // Cached for performance
department_budget: 500000 // Denormalized
}
// Use lookup when you need all data
// Update cached data with background syncSubset Pattern
// Split large documents into smaller subsets
// Main document with summary
db.products.findOne()
{
_id: ObjectId("prod1"),
name: "Popular Book",
author: "John Smith",
reviews_count: 1500,
rating: 4.5,
review_ids: [
ObjectId("rev1"),
ObjectId("rev2"),
// ... only recent reviews
]
}
// Reviews in separate collection
db.product_reviews.findOne()
{
_id: ObjectId("rev1"),
product_id: ObjectId("prod1"),
user: "Jane",
rating: 5,
comment: "Excellent book!"
}Aggregation Framework Patterns
// Complex multi-stage aggregation
db.employees.aggregate([
// Stage 1: Match
{
$match: { department: "Engineering", active: true }
},
// Stage 2: Group
{
$group: {
_id: "$department",
count: { $sum: 1 },
avg_salary: { $avg: "$salary" },
min_salary: { $min: "$salary" },
max_salary: { $max: "$salary" },
total_salary: { $sum: "$salary" }
}
},
// Stage 3: Sort
{
$sort: { avg_salary: -1 }
},
// Stage 4: Project
{
$project: {
department: "$_id",
employee_count: "$count",
average_salary: "$avg_salary",
salary_range: {
min: "$min_salary",
max: "$max_salary"
},
_id: 0
}
}
])
// Lookup (join) in aggregation
db.orders.aggregate([
{
$lookup: {
from: "customers",
localField: "customer_id",
foreignField: "_id",
as: "customer_info"
}
},
{ $unwind: "$customer_info" },
{
$group: {
_id: "$customer_info.city",
total_orders: { $sum: 1 },
total_amount: { $sum: "$amount" }
}
}
])Scaling Patterns
Sharding Strategy
// Shard by ranges (bad - uneven distribution)
// sh.shardCollection("mydb.logs", { date: 1 })
// Shard by hash (good - even distribution)
sh.shardCollection("mydb.events", { user_id: "hashed" })
// Compound shard key
sh.shardCollection("mydb.orders", { customer_id: 1, order_date: -1 })Bulk Insert Pattern
// Batch inserts for performance
const batch = []
for (let i = 0; i < 10000; i++) {
batch.push({
name: `Item ${i}`,
value: Math.random() * 1000
})
if (batch.length === 1000) {
db.items.insertMany(batch)
batch = []
}
}
if (batch.length > 0) {
db.items.insertMany(batch)
}Best Practices
✅ Embed when data is accessed together ✅ Reference when data is large or accessed separately ✅ Denormalize for read performance ✅ Keep related data close ✅ Use indexes on query fields ✅ Limit array sizes (16MB document limit) ✅ Use bulk operations for large inserts ✅ Monitor document growth ✅ Plan for evolving schemas
mongodb Guide
#!/usr/bin/env python3
import json
print(json.dumps({"skill": "mongodb"}, indent=2))
Related skills
FAQ
What does mongodb do?
mongodb is a Claude Code skill for ai & agent building.
When should I use mongodb?
When you need to helps with ai & agent building tasks., or when mongodb is a claude code skill for ai & agent building.
What are the main capabilities?
mongodb; AI & Agent Building; AI-coding skill.