Database Expert
cin12211/orca-q
Database performance optimization, schema design, query analysis, and connection management across PostgreSQL, MySQL, MongoDB, and SQLite with ORM integration.
Guide for implementing MongoDB - a document database platform with CRUD operations, aggregation pipelines, indexing, replication, sharding, search capabilities, and comprehensive security.
$ npx skills add einverne/dotfiles --skill mongodb -a claude-codeProject install by default; add -g for ~/.claude/skills/.
$ gh skill install einverne/dotfiles mongodb --agent claude-codeProject scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).
$ git clone --depth 1 https://github.com/einverne/dotfiles.git skills-src && mkdir -p .claude/skills && cp -r skills-src/claude/skills/mongodb .claude/skills/mongodb && rm -rf skills-srcUse ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.
Claude Code skills documentation · loads skills from .claude/skills/
Install the "mongodb" agent skill from https://github.com/einverne/dotfiles/tree/master/claude/skills/mongodb into .claude/skills/mongodb/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "mongodb", then confirm the skill loads.Claude Code copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$skill-installer install https://github.com/einverne/dotfiles/tree/master/claude/skills/mongodbType this inside Codex. $skill-installer <name> installs a curated skill from openai/skills. The installer writes to $CODEX_HOME/skills (default ~/.codex/skills). Restart Codex if the skill does not show up.
$ npx skills add einverne/dotfiles --skill mongodb -a codexProject install goes to .agents/skills/; add -g for ~/.codex/skills/.
$ gh skill install einverne/dotfiles mongodb --agent codexProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/einverne/dotfiles.git skills-src && mkdir -p .agents/skills && cp -r skills-src/claude/skills/mongodb .agents/skills/mongodb && rm -rf skills-srcUse ~/.agents/skills/ instead of .agents/skills for a personal install.
Codex skills documentation · loads skills from .agents/skills/
Install the "mongodb" agent skill from https://github.com/einverne/dotfiles/tree/master/claude/skills/mongodb into .agents/skills/mongodb/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "mongodb", then confirm the skill loads.Codex copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add einverne/dotfiles --skill mongodb -a cursorProject install goes to .agents/skills/; add -g for ~/.cursor/skills/.
$ gh skill install einverne/dotfiles mongodb --agent cursorProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/einverne/dotfiles.git skills-src && mkdir -p .cursor/skills && cp -r skills-src/claude/skills/mongodb .cursor/skills/mongodb && rm -rf skills-srcUse ~/.cursor/skills/ instead of .cursor/skills for a personal install.
Cursor skills documentation · loads skills from .cursor/skills/, .agents/skills/, .claude/skills/, .codex/skills/
Install the "mongodb" agent skill from https://github.com/einverne/dotfiles/tree/master/claude/skills/mongodb into .cursor/skills/mongodb/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "mongodb", then confirm the skill loads.Cursor copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gemini skills install https://github.com/einverne/dotfiles.git --path claude/skills/mongodb--scope user (default) or --scope workspace; --path is the subfolder of the repo that holds the skill; --consent skips the security confirmation prompt.
$ npx skills add einverne/dotfiles --skill mongodb -a gemini-cliProject install goes to .agents/skills/; add -g for ~/.gemini/skills/.
$ gh skill install einverne/dotfiles mongodb --agent gemini-cliProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/einverne/dotfiles.git skills-src && mkdir -p .gemini/skills && cp -r skills-src/claude/skills/mongodb .gemini/skills/mongodb && rm -rf skills-srcUse ~/.gemini/skills/ instead of .gemini/skills for a personal install, then run /skills reload.
Gemini CLI skills documentation · loads skills from .gemini/skills/, .agents/skills/
Install the "mongodb" agent skill from https://github.com/einverne/dotfiles/tree/master/claude/skills/mongodb into .gemini/skills/mongodb/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "mongodb", then confirm the skill loads.Gemini CLI copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gh skill install einverne/dotfiles mongodbInstalls for Copilot at project scope by default; add --scope user for a personal install. Preview a skill first with gh skill preview. Needs GitHub CLI 2.90.0 or later (public preview).
$ npx skills add einverne/dotfiles --skill mongodb -a github-copilotProject install goes to .agents/skills/; add -g for ~/.copilot/skills/.
$ git clone --depth 1 https://github.com/einverne/dotfiles.git skills-src && mkdir -p .github/skills && cp -r skills-src/claude/skills/mongodb .github/skills/mongodb && rm -rf skills-srcUse ~/.copilot/skills/ instead of .github/skills for a personal install. Commit .github/skills so cloud agent and code review can use it.
GitHub Copilot skills documentation · loads skills from .github/skills/, .claude/skills/, .agents/skills/
Install the "mongodb" agent skill from https://github.com/einverne/dotfiles/tree/master/claude/skills/mongodb into .github/skills/mongodb/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "mongodb", then confirm the skill loads.GitHub Copilot copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add einverne/dotfiles --skill mongodb -a opencodeOpenCode documents no install command of its own. Project install goes to .agents/skills/; add -g for ~/.config/opencode/skills/.
$ gh skill install einverne/dotfiles mongodb --agent opencodeProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/einverne/dotfiles.git skills-src && mkdir -p .opencode/skills && cp -r skills-src/claude/skills/mongodb .opencode/skills/mongodb && rm -rf skills-srcUse ~/.config/opencode/skills/ instead of .opencode/skills for a personal install.
OpenCode skills documentation · loads skills from .opencode/skills/, .claude/skills/, .agents/skills/
Install the "mongodb" agent skill from https://github.com/einverne/dotfiles/tree/master/claude/skills/mongodb into .opencode/skills/mongodb/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "mongodb", then confirm the skill loads.OpenCode copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
mongodbGuide for implementing MongoDB - a document database platform with CRUD operations, aggregation pipelines, indexing, replication, sharding, search capabilities, and comprehensive security.
Mongodb is an agent skill from einverne/dotfiles. Guide for implementing MongoDB - a document database platform with CRUD operations, aggregation pipelines, indexing, replication, sharding, search capabilities, and comprehensive security. Use when working with MongoDB databases, designing schemas, writing queries, optimizing performance, configuring deployments (Atlas/self-managed/Kubernetes), implementing security, or integrating with applications through 15+ official drivers. (project)
Its SKILL.md is about 8k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.
It sits in Databases, covering NoSQL databases and Database administration. It works with MongoDB and Kubernetes. The repository describes itself as: my personal dotfiles managed by dotbot, zinit. The licence is GPL-3.0.
6 steps, taken from the first numbered list in SKILL.md.
Read from SKILL.md and the folder at commit c6c0686. It shows what the files ask for, not the result of running them.
Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.
From allowed-tools in the SKILL.md frontmatter.
Shell commands in SKILL.md call:
apt-getwgetFrom the folder's file list and the shell code blocks in SKILL.md.
Hosts in commands or code, which the agent is likely to contact:
mongodb.orgrepo.mongodb.orgAlso links to:
mongodb.comFrom URLs in SKILL.md, links to its own repository left out.
Names no API keys, tokens, secrets or passwords.
From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.
Mongodb loads about 8k tokens when it runs. Until then it costs about 113 tokens; SKILL.md has 1,175 words of instructions outside code blocks.
Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.
The automated check noted patterns worth knowing about, such as sudo or a known installer.
.mongodb.org/static/pgp/server-8.0.asc | sudo apt-key add -untu jammy/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.listsudo apt-get updatesudo apt-get install -y mongodb-orgsudo systemctl start mongodsudo systemctl enable mongodAutomated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.
The full file from einverne/dotfiles at commit c6c0686, republished under its GPL-3.0 licence (© einverne). 1,175 words, ~7,954 tokens.
.claude/skills/mongodb/SKILL.md (or your agent's skills folder).A comprehensive guide for working with MongoDB - a document-oriented database platform that provides powerful querying, horizontal scaling, high availability, and enterprise-grade security.
Use this skill when you need to:
This skill synthesizes 24,618 documentation links across 172 major MongoDB sections, covering:
// Find documents
db.collection.find({ status: "active" })
db.collection.findOne({ _id: ObjectId("...") })
// Query operators
db.users.find({ age: { $gte: 18, $lt: 65 } })
db.posts.find({ tags: { $in: ["mongodb", "database"] } })
db.products.find({ price: { $exists: true } })
// Projection (select specific fields)
db.users.find({ status: "active" }, { name: 1, email: 1 })
// Cursor operations
db.collection.find().sort({ createdAt: -1 }).limit(10).skip(20)// Insert
db.collection.insertOne({ name: "Alice", age: 30 })
db.collection.insertMany([{ name: "Bob" }, { name: "Charlie" }])
// Update
db.users.updateOne(
{ _id: userId },
{ $set: { status: "verified" } }
)
db.users.updateMany(
{ lastLogin: { $lt: cutoffDate } },
{ $set: { status: "inactive" } }
)
// Replace entire document
db.users.replaceOne({ _id: userId }, newUserDoc)
// Delete
db.users.deleteOne({ _id: userId })
db.users.deleteMany({ status: "deleted" })
// Upsert (update or insert if not exists)
db.users.updateOne(
{ email: "user@example.com" },
{ $set: { name: "User", lastSeen: new Date() } },
{ upsert: true }
)// Increment counter
db.posts.updateOne(
{ _id: postId },
{ $inc: { views: 1 } }
)
// Add to array (if not exists)
db.users.updateOne(
{ _id: userId },
{ $addToSet: { interests: "mongodb" } }
)
// Push to array
db.posts.updateOne(
{ _id: postId },
{ $push: { comments: { author: "Alice", text: "Great!" } } }
)
// Find and modify atomically
db.counters.findAndModify({
query: { _id: "sequence" },
update: { $inc: { value: 1 } },
new: true,
upsert: true
})$eq, $ne, $gt, $gte, $lt, $lte
$in, $nin$and, $or, $not, $nor
// Example
db.products.find({
$and: [
{ price: { $gte: 100 } },
{ stock: { $gt: 0 } }
]
})$all, $elemMatch, $size
$firstN, $lastN, $maxN, $minN
// Example: Find docs with all tags
db.posts.find({ tags: { $all: ["mongodb", "database"] } })
// Match array element with multiple conditions
db.products.find({
reviews: {
$elemMatch: { rating: { $gte: 4 }, verified: true }
}
})$exists, $type
// Find documents with optional field
db.users.find({ phoneNumber: { $exists: true } })
// Type checking
db.data.find({ value: { $type: "string" } })MongoDB's most powerful feature for data transformation and analysis.
db.orders.aggregate([
// Stage 1: Filter documents
{ $match: { status: "completed", total: { $gte: 100 } } },
// Stage 2: Join with customers
{ $lookup: {
from: "customers",
localField: "customerId",
foreignField: "_id",
as: "customer"
}},
// Stage 3: Unwind array
{ $unwind: "$items" },
// Stage 4: Group and aggregate
{ $group: {
_id: "$items.category",
totalRevenue: { $sum: "$items.total" },
orderCount: { $sum: 1 },
avgOrderValue: { $avg: "$total" }
}},
// Stage 5: Sort results
{ $sort: { totalRevenue: -1 } },
// Stage 6: Limit results
{ $limit: 10 },
// Stage 7: Reshape output
{ $project: {
category: "$_id",
revenue: "$totalRevenue",
orders: "$orderCount",
avgValue: { $round: ["$avgOrderValue", 2] },
_id: 0
}}
])Time-Based Aggregation:
db.events.aggregate([
{ $match: { timestamp: { $gte: startDate, $lt: endDate } } },
{ $group: {
_id: {
year: { $year: "$timestamp" },
month: { $month: "$timestamp" },
day: { $dayOfMonth: "$timestamp" }
},
count: { $sum: 1 }
}}
])Faceted Search (Multiple Aggregations):
db.products.aggregate([
{ $match: { category: "electronics" } },
{ $facet: {
priceRanges: [
{ $bucket: {
groupBy: "$price",
boundaries: [0, 100, 500, 1000, 5000],
default: "5000+",
output: { count: { $sum: 1 } }
}}
],
topBrands: [
{ $group: { _id: "$brand", count: { $sum: 1 } } },
{ $sort: { count: -1 } },
{ $limit: 5 }
],
avgPrice: [
{ $group: { _id: null, avg: { $avg: "$price" } } }
]
}}
])Window Functions:
db.sales.aggregate([
{ $setWindowFields: {
partitionBy: "$region",
sortBy: { date: 1 },
output: {
runningTotal: { $sum: "$amount", window: { documents: ["unbounded", "current"] } },
movingAvg: { $avg: "$amount", window: { documents: [-7, 0] } }
}
}}
])Math Operators:
$add, $subtract, $multiply, $divide, $mod
$abs, $ceil, $floor, $round, $sqrt, $pow
$log, $log10, $ln, $expString Operators:
$concat, $substr, $toLower, $toUpper
$trim, $ltrim, $rtrim, $split
$regexMatch, $regexFind, $regexFindAllArray Operators:
$arrayElemAt, $slice, $first, $last, $reverse
$sortArray, $filter, $map, $reduce
$zip, $concatArraysDate/Time Operators:
$dateAdd, $dateDiff, $dateFromString, $dateToString
$dayOfMonth, $month, $year, $dayOfWeek
$week, $hour, $minute, $secondType Conversion:
$toInt, $toString, $toDate, $toDouble
$toDecimal, $toObjectId, $toBooldb.users.createIndex({ email: 1 }) // ascending
db.posts.createIndex({ createdAt: -1 }) // descending// Order matters! Index on { status: 1, createdAt: -1 }
db.orders.createIndex({ status: 1, createdAt: -1 })
// Supports queries on:
// - { status: "..." }
// - { status: "...", createdAt: ... }
// Does NOT efficiently support: { createdAt: ... } alonedb.articles.createIndex({ title: "text", body: "text" })
// Search
db.articles.find({ $text: { $search: "mongodb database" } })
// With relevance score
db.articles.find(
{ $text: { $search: "mongodb" } },
{ score: { $meta: "textScore" } }
).sort({ score: { $meta: "textScore" } })// 2dsphere for earth-like geometry
db.places.createIndex({ location: "2dsphere" })
// Find nearby
db.places.find({
location: {
$near: {
$geometry: { type: "Point", coordinates: [lon, lat] },
$maxDistance: 5000 // meters
}
}
})// Index all fields in subdocuments
db.products.createIndex({ "attributes.$**": 1 })
// Supports queries on any field under attributes
db.products.find({ "attributes.color": "red" })// Index only documents matching filter
db.orders.createIndex(
{ customerId: 1 },
{ partialFilterExpression: { status: "active" } }
)// Delete documents 24 hours after createdAt
db.sessions.createIndex(
{ createdAt: 1 },
{ expireAfterSeconds: 86400 }
)db.users.createIndex({ userId: "hashed" })// Basic explain
db.users.find({ email: "user@example.com" }).explain()
// Execution stats (shows actual performance)
db.users.find({ age: { $gte: 18 } }).explain("executionStats")
// Key metrics to check:
// - executionTimeMillis
// - totalDocsExamined vs. nReturned (should be close)
// - stage: "IXSCAN" (using index) vs. "COLLSCAN" (full scan - BAD)// Create index
db.users.createIndex({ email: 1, name: 1 })
// Query covered by index (no document fetch needed)
db.users.find(
{ email: "user@example.com" },
{ email: 1, name: 1, _id: 0 } // project only indexed fields
)// Force specific index
db.users.find({ status: "active", city: "NYC" })
.hint({ status: 1, createdAt: -1 })// List all indexes
db.collection.getIndexes()
// Drop index
db.collection.dropIndex("indexName")
// Hide index (test before dropping)
db.collection.hideIndex("indexName")
db.collection.unhideIndex("indexName")
// Index stats
db.collection.aggregate([{ $indexStats: {} }])// User with single address
{
_id: ObjectId("..."),
name: "Alice",
email: "alice@example.com",
address: {
street: "123 Main St",
city: "NYC",
zipcode: "10001"
}
}// Blog post with comments (< 100 comments)
{
_id: ObjectId("..."),
title: "MongoDB Guide",
comments: [
{ author: "Bob", text: "Great post!", date: ISODate("...") },
{ author: "Charlie", text: "Thanks!", date: ISODate("...") }
]
}// Author collection
{ _id: ObjectId("author1"), name: "Alice" }
// Books collection (many books per author)
{ _id: ObjectId("book1"), title: "Book 1", authorId: ObjectId("author1") }
{ _id: ObjectId("book2"), title: "Book 2", authorId: ObjectId("author1") }// Users collection
{
_id: ObjectId("user1"),
name: "Alice",
groupIds: [ObjectId("group1"), ObjectId("group2")]
}
// Groups collection
{
_id: ObjectId("group1"),
name: "MongoDB Users",
memberIds: [ObjectId("user1"), ObjectId("user2")]
}// High-frequency sensor data
{
_id: ObjectId("..."),
sensorId: "sensor-123",
timestamp: ISODate("2025-01-01T00:00:00Z"),
readings: [
{ time: 0, temp: 23.5, humidity: 45 },
{ time: 60, temp: 23.6, humidity: 46 },
{ time: 120, temp: 23.4, humidity: 45 }
]
}
// Create time series collection
db.createCollection("sensor_data", {
timeseries: {
timeField: "timestamp",
metaField: "sensorId",
granularity: "minutes"
}
})// User document with pre-computed stats
{
_id: ObjectId("..."),
username: "alice",
stats: {
postCount: 150,
followerCount: 2500,
lastUpdated: ISODate("...")
}
}
// Update stats periodically or with triggers// Support schema evolution
{
_id: ObjectId("..."),
schemaVersion: 2,
// v2 fields
name: { first: "Alice", last: "Smith" },
// Migration code handles v1 format
}db.createCollection("users", {
validator: {
$jsonSchema: {
bsonType: "object",
required: ["email", "name"],
properties: {
email: {
bsonType: "string",
pattern: "^.+@.+$",
description: "must be a valid email"
},
age: {
bsonType: "int",
minimum: 0,
maximum: 120
},
status: {
enum: ["active", "inactive", "pending"]
}
}
}
},
validationLevel: "strict", // or "moderate"
validationAction: "error" // or "warn"
})Architecture:
Configuration:
rs.initiate({
_id: "myReplicaSet",
members: [
{ _id: 0, host: "mongo1:27017" },
{ _id: 1, host: "mongo2:27017" },
{ _id: 2, host: "mongo3:27017" }
]
})
// Check status
rs.status()
// Add member
rs.add("mongo4:27017")
// Remove member
rs.remove("mongo4:27017")Controls acknowledgment of write operations:
// Wait for majority acknowledgment (durable)
db.users.insertOne(
{ name: "Alice" },
{ writeConcern: { w: "majority", wtimeout: 5000 } }
)
// Common levels:
// w: 1 - primary acknowledges (default)
// w: "majority" - majority of nodes acknowledge (recommended for production)
// w: <number> - specific number of nodes
// w: 0 - no acknowledgment (fire and forget)Controls where reads are served from:
// Options:
// - primary (default): read from primary only
// - primaryPreferred: primary if available, else secondary
// - secondary: read from secondary only
// - secondaryPreferred: secondary if available, else primary
// - nearest: lowest network latency
db.collection.find().readPref("secondaryPreferred")Multi-document ACID transactions:
const session = client.startSession();
session.startTransaction();
try {
await accounts.updateOne(
{ _id: fromAccount },
{ $inc: { balance: -amount } },
{ session }
);
await accounts.updateOne(
{ _id: toAccount },
{ $inc: { balance: amount } },
{ session }
);
await session.commitTransaction();
} catch (error) {
await session.abortTransaction();
throw error;
} finally {
session.endSession();
}Components:
CRITICAL: Shard key determines data distribution and query performance.
Good Shard Keys:
// Enable sharding on database
sh.enableSharding("myDatabase")
// Shard collection with hashed key
sh.shardCollection(
"myDatabase.users",
{ userId: "hashed" }
)
// Shard with compound key
sh.shardCollection(
"myDatabase.orders",
{ customerId: 1, orderDate: 1 }
)Assign data ranges to specific shards:
// Add shard tags
sh.addShardTag("shard0", "US-EAST")
sh.addShardTag("shard1", "US-WEST")
// Assign ranges to zones
sh.addTagRange(
"myDatabase.users",
{ zipcode: "00000" },
{ zipcode: "50000" },
"US-EAST"
)// Targeted query (includes shard key) - fast
db.users.find({ userId: "12345" })
// Scatter-gather (no shard key) - slow
db.users.find({ email: "user@example.com" })Methods:
// Create admin user
use admin
db.createUser({
user: "admin",
pwd: "strongPassword",
roles: ["root"]
})
// Create database user
use myDatabase
db.createUser({
user: "appUser",
pwd: "password",
roles: [
{ role: "readWrite", db: "myDatabase" }
]
})Built-in Roles:
read, readWrite: Collection-leveldbAdmin, dbOwner: Database administrationuserAdmin: User managementclusterAdmin: Cluster managementroot: SuperuserCustom Roles:
db.createRole({
role: "customRole",
privileges: [
{
resource: { db: "myDatabase", collection: "users" },
actions: ["find", "update"]
}
],
roles: []
})// Configure in mongod.conf
security:
enableEncryption: true
encryptionKeyFile: /path/to/keyfile// mongod.conf
net:
tls:
mode: requireTLS
certificateKeyFile: /path/to/cert.pem
CAFile: /path/to/ca.pem// Automatic encryption of sensitive fields
const clientEncryption = new ClientEncryption(client, {
keyVaultNamespace: "encryption.__keyVault",
kmsProviders: {
aws: {
accessKeyId: "...",
secretAccessKey: "..."
}
}
})
// Create data key
const dataKeyId = await clientEncryption.createDataKey("aws", {
masterKey: { region: "us-east-1", key: "..." }
})
// Configure auto-encryption
const encryptedClient = new MongoClient(uri, {
autoEncryption: {
keyVaultNamespace: "encryption.__keyVault",
kmsProviders: { aws: {...} },
schemaMap: {
"myDatabase.users": {
bsonType: "object",
properties: {
ssn: {
encrypt: {
keyId: [dataKeyId],
algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
}
}
}
}
}
}
})Recommended for most use cases.
Quick Start:
Features:
Connection:
const uri = "mongodb+srv://user:pass@cluster.mongodb.net/database?retryWrites=true&w=majority";
const client = new MongoClient(uri);Installation:
# Ubuntu/Debian
wget -qO - https://www.mongodb.org/static/pgp/server-8.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
# Start
sudo systemctl start mongod
sudo systemctl enable mongodConfiguration (mongod.conf):
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
systemLog:
destination: file
path: /var/log/mongodb/mongod.log
logAppend: true
net:
port: 27017
bindIp: 127.0.0.1
security:
authorization: enabled
replication:
replSetName: "myReplicaSet"MongoDB Kubernetes Operator:
apiVersion: mongodbcommunity.mongodb.com/v1
kind: MongoDBCommunity
metadata:
name: mongodb-replica-set
spec:
members: 3
type: ReplicaSet
version: "8.0"
security:
authentication:
modes: ["SCRAM"]
users:
- name: admin
db: admin
passwordSecretRef:
name: mongodb-admin-password
roles:
- name: root
db: admin
statefulSet:
spec:
volumeClaimTemplates:
- metadata:
name: data-volume
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 10Giconst { MongoClient } = require("mongodb");
const client = new MongoClient(uri);
await client.connect();
const db = client.db("myDatabase");
const collection = db.collection("users");
// CRUD
await collection.insertOne({ name: "Alice" });
const user = await collection.findOne({ name: "Alice" });
await collection.updateOne({ name: "Alice" }, { $set: { age: 30 } });
await collection.deleteOne({ name: "Alice" });from pymongo import MongoClient
client = MongoClient(uri)
db = client.myDatabase
collection = db.users
# CRUD
collection.insert_one({"name": "Alice"})
user = collection.find_one({"name": "Alice"})
collection.update_one({"name": "Alice"}, {"$set": {"age": 30}})
collection.delete_one({"name": "Alice"})MongoClient mongoClient = MongoClients.create(uri);
MongoDatabase database = mongoClient.getDatabase("myDatabase");
MongoCollection<Document> collection = database.getCollection("users");
// Insert
collection.insertOne(new Document("name", "Alice"));
// Find
Document user = collection.find(eq("name", "Alice")).first();
// Update
collection.updateOne(eq("name", "Alice"), set("age", 30));client, _ := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
collection := client.Database("myDatabase").Collection("users")
// Insert
collection.InsertOne(context.TODO(), bson.M{"name": "Alice"})
// Find
var user bson.M
collection.FindOne(context.TODO(), bson.M{"name": "Alice"}).Decode(&user){
"connector.class": "com.mongodb.kafka.connect.MongoSinkConnector",
"connection.uri": "mongodb://localhost:27017",
"database": "myDatabase",
"collection": "events",
"topics": "my-topic"
}val df = spark.read
.format("mongodb")
.option("uri", "mongodb://localhost:27017/myDatabase.myCollection")
.load()
df.filter($"age" > 18).show()-- Query MongoDB using SQL
SELECT name, AVG(age) as avg_age
FROM users
WHERE status = 'active'
GROUP BY name;Create Search Index:
{
"mappings": {
"dynamic": false,
"fields": {
"title": {
"type": "string",
"analyzer": "lucene.standard"
},
"description": {
"type": "string",
"analyzer": "lucene.english"
}
}
}
}Query:
db.articles.aggregate([
{
$search: {
text: {
query: "mongodb database",
path: ["title", "description"],
fuzzy: { maxEdits: 1 }
}
}
},
{ $limit: 10 },
{ $project: { title: 1, description: 1, score: { $meta: "searchScore" } } }
])For AI/ML similarity search:
db.products.aggregate([
{
$vectorSearch: {
index: "vector_index",
path: "embedding",
queryVector: [0.123, 0.456, ...], // 1536 dimensions for OpenAI
numCandidates: 100,
limit: 10
}
},
{
$project: {
name: 1,
description: 1,
score: { $meta: "vectorSearchScore" }
}
}
])const changeStream = collection.watch([
{ $match: { "fullDocument.status": "active" } }
]);
changeStream.on("change", (change) => {
console.log("Change detected:", change);
// change.operationType: "insert", "update", "delete", "replace"
// change.fullDocument: entire document (if configured)
});
// Resume from specific point
const resumeToken = changeStream.resumeToken;
const newStream = collection.watch([], { resumeAfter: resumeToken });const bulkOps = [
{ insertOne: { document: { name: "Alice", age: 30 } } },
{ updateOne: {
filter: { name: "Bob" },
update: { $set: { age: 25 } },
upsert: true
}},
{ deleteOne: { filter: { name: "Charlie" } } }
];
const result = await collection.bulkWrite(bulkOps, { ordered: false });
console.log(`Inserted: ${result.insertedCount}, Updated: ${result.modifiedCount}`);Index Critical Fields
Use Projection
// Good: Only return needed fields
db.users.find({ status: "active" }, { name: 1, email: 1 })
// Bad: Return entire document
db.users.find({ status: "active" })Limit Result Sets
db.users.find().limit(100)Use Aggregation Pipeline
$match early to filter$project to reduce document sizeConnection Pooling
const client = new MongoClient(uri, {
maxPoolSize: 50,
minPoolSize: 10
});Batch Writes
// Good: Batch insert
await collection.insertMany(documents);
// Bad: Individual inserts
for (const doc of documents) {
await collection.insertOne(doc);
}Write Concern Tuning
w: 1 for non-critical writes (faster)w: "majority" for critical data (safer)Read Preference
secondary for read-heavy analyticsprimary for strong consistency// Check slow queries
db.setProfilingLevel(1, { slowms: 100 })
db.system.profile.find().sort({ ts: -1 }).limit(10)
// Current operations
db.currentOp()
// Server status
db.serverStatus()
// Collection stats
db.collection.stats()| Error | Cause | Solution |
|---|---|---|
MongoNetworkError | Connection failed | Check network, IP whitelist, credentials |
E11000 duplicate key | Duplicate unique field | Check unique indexes, handle duplicates |
ValidationError | Schema validation failed | Check document structure, field types |
OperationTimeout | Query too slow | Add indexes, optimize query, increase timeout |
AggregationResultTooLarge | Result > 16MB | Use $limit, $project, or $out |
InvalidSharKey | Bad shard key | Choose high-cardinality, even-distribution key |
ChunkTooBig | Jumbo chunk | Use refineShardKey or re-shard |
OplogTailFailed | Replication lag | Check network, increase oplog size |
// Explain query plan
db.collection.find({ field: value }).explain("executionStats")
// Check index usage
db.collection.aggregate([{ $indexStats: {} }])
// Analyze slow queries
db.setProfilingLevel(2) // Profile all queries
db.system.profile.find({ millis: { $gt: 100 } })
// Check replication lag
rs.printReplicationInfo()
rs.printSecondaryReplicationInfo()find() - Query documentsupdateOne() / updateMany() - Modify documentsinsertOne() / insertMany() - Add documentsdeleteOne() / deleteMany() - Remove documentsaggregate() - Complex queriescreateIndex() - Performance optimizationexplain() - Query analysisfindOne() - Get single documentcountDocuments() - Count matchesreplaceOne() - Replace documentdistinct() - Get unique valuesbulkWrite() - Batch operationsfindAndModify() - Atomic updatewatch() - Monitor changessort() / limit() / skip() - Result manipulation$lookup - Join collections$group - Aggregate data$match - Filter pipeline$project - Shape outputhint() - Force indexPagination:
const page = 2;
const pageSize = 20;
db.collection.find()
.skip((page - 1) * pageSize)
.limit(pageSize)Cursor-based Pagination (Better):
const lastId = ObjectId("...");
db.collection.find({ _id: { $gt: lastId } })
.limit(20)Atomic Counter:
db.counters.findAndModify({
query: { _id: "sequence" },
update: { $inc: { value: 1 } },
new: true,
upsert: true
})Soft Delete:
// Mark as deleted
db.users.updateOne({ _id: userId }, { $set: { deleted: true, deletedAt: new Date() } })
// Query active only
db.users.find({ deleted: { $ne: true } })w: "majority" for critical dataThis skill provides comprehensive MongoDB knowledge for implementing database solutions, from basic CRUD operations to advanced distributed systems with sharding, replication, and security. Always refer to official documentation for the latest features and version-specific details.
© einverne, GPL-3.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file
Just SKILL.md in claude/skills/mongodb of einverne/dotfiles.
Open the folder on GitHubat commit c6c0686
Mongodb next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.
| Skill | Stars | Used in | Tokens | Auto-check | Licence | Repo updated |
|---|---|---|---|---|---|---|
| Mongodb this skilleinverne/dotfiles | 121 | — | ~8k | Automated safety check: Notes | GPL-3.0 | |
| Database Expertcin12211/orca-q | 224 | — | ~2.8k | Automated safety check: Pass | MIT | |
| DB SculptorEliasOulkadi/shokunin | 114 | — | ~3.1k | Automated safety check: Notes | MIT | |
| Discover Databaserand/cc-polymath | 181 | — | ~2k | Automated safety check: Pass | MIT | |
| Whodbxiaoyuge886/aigc | 198 | — | ~894 | Automated safety check: Pass | MIT | |
| Mongodbsickn33/agentic-awesome-skills | 47k | 2 repos | ~2.7k | Automated safety check: Notes | MIT |
cin12211/orca-q
Database performance optimization, schema design, query analysis, and connection management across PostgreSQL, MySQL, MongoDB, and SQLite with ORM integration.
EliasOulkadi/shokunin
Design database schemas with Prisma/Drizzle, PostgreSQL index strategy (B-tree, GIN, GiST, BRIN, Hash), query optimization (EXPLAIN ANALYZE), migration safety (expand/contract, zero-downtime), and…
rand/cc-polymath
Automatically discover database skills when working with SQL, PostgreSQL, MongoDB, Redis, database schema design, query optimization, migrations, connection pooling, ORMs, or database selection.
xiaoyuge886/aigc
Database operations including querying, schema exploration, and data analysis.
sickn33/agentic-awesome-skills
Administer MongoDB databases. An agent skill from sickn33/agentic-awesome-skills.
jeremylongshore/tons-of-skills-marketplace
Automate database backup processes with scheduling, compression, and encryption.
einverne/dotfiles
Comprehensive document creation, editing, and analysis with support for tracked changes, comments, formatting preservation, and text extraction.
einverne/dotfiles
Browser automation, debugging, and performance analysis using Puppeteer CLI scripts.
einverne/dotfiles
Comprehensive PDF manipulation toolkit for extracting text and tables, creating new PDFs, merging/splitting documents, and handling forms.
einverne/dotfiles
Guide for implementing Google Gemini API audio capabilities - analyze audio with transcription, summarization, and understanding (up to 9.5 hours), plus generate speech with controllable TTS.
einverne/dotfiles
Guide for implementing Google Gemini API document processing - analyze PDFs with native vision to extract text, images, diagrams, charts, and tables.
einverne/dotfiles
Presentation creation, editing, and analysis. An agent skill from einverne/dotfiles.
Works with
Categories
Guide for implementing MongoDB - a document database platform with CRUD operations, aggregation pipelines, indexing, replication, sharding, search capabilities, and comprehensive security. Mongodb is an agent skill from einverne/dotfiles. Guide for implementing MongoDB - a document database platform with CRUD operations, aggregation pipelines, indexing, replication, sharding, search capabilities, and comprehensive security.
Mongodb fits situations like: working with MongoDB databases; designing schemas; writing queries; optimizing performance.
Run `npx skills add einverne/dotfiles --skill mongodb -a claude-code`. Or copy the skill folder (claude/skills/mongodb in einverne/dotfiles) into .claude/skills/mongodb in your project. Claude Code loads it when a task matches its description.
Run `npx skills add einverne/dotfiles --skill mongodb -a codex`. Or copy the skill folder (claude/skills/mongodb in einverne/dotfiles) into .agents/skills/mongodb in your project. Codex loads it when a task matches its description.
Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add einverne/dotfiles --skill mongodb -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/mongodb, .gemini/skills/mongodb, .github/skills/mongodb and .opencode/skills/mongodb in your project.
Going by SKILL.md and its folder, Mongodb needs the command-line tools its instructions call (apt-get and wget).
SKILL.md names 3 domains. In commands or code: mongodb.org and repo.mongodb.org; the agent is likely to contact these when it follows the instructions. As links in the text: mongodb.com. This is read from the text; nothing was executed.
Our automated static check of SKILL.md found notes only (runs commands with sudo), nothing it rates as a warning. It is not a guarantee. Review the folder before installing.
Mongodb is published under the GPL-3.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.
About 8k tokens (SKILL.md is roughly 32k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.
Skills that share tags, products or a category with Mongodb: Database Expert (cin12211/orca-q, 224 stars), DB Sculptor (EliasOulkadi/shokunin, 114 stars), Discover Database (rand/cc-polymath, 181 stars) and Whodb (xiaoyuge886/aigc, 198 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.
einverne (a GitHub user) maintains it in einverne/dotfiles, which has 121 GitHub stars. The repository holds 39 skills in this directory. The repository was last updated on September 9, 2026.
Source: einverne/dotfiles on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.