$npx -y skills add jackspace/ClaudeSkillz --skill databases_mrgoonieWork with MongoDB (document database, BSON documents, aggregation pipelines, Atlas cloud) and PostgreSQL (relational database, SQL queries, psql CLI, pgAdmin). Use when designing database schemas, writing queries and aggregations, optimizing indexes for performance, performing da
| 1 | # Databases Skill |
| 2 | |
| 3 | Unified guide for working with MongoDB (document-oriented) and PostgreSQL (relational) databases. Choose the right database for your use case and master both systems. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | Use when: |
| 8 | - Designing database schemas and data models |
| 9 | - Writing queries (SQL or MongoDB query language) |
| 10 | - Building aggregation pipelines or complex joins |
| 11 | - Optimizing indexes and query performance |
| 12 | - Implementing database migrations |
| 13 | - Setting up replication, sharding, or clustering |
| 14 | - Configuring backups and disaster recovery |
| 15 | - Managing database users and permissions |
| 16 | - Analyzing slow queries and performance issues |
| 17 | - Administering production database deployments |
| 18 | |
| 19 | ## Database Selection Guide |
| 20 | |
| 21 | ### Choose MongoDB When: |
| 22 | - Schema flexibility: frequent structure changes, heterogeneous data |
| 23 | - Document-centric: natural JSON/BSON data model |
| 24 | - Horizontal scaling: need to shard across multiple servers |
| 25 | - High write throughput: IoT, logging, real-time analytics |
| 26 | - Nested/hierarchical data: embedded documents preferred |
| 27 | - Rapid prototyping: schema evolution without migrations |
| 28 | |
| 29 | **Best for:** Content management, catalogs, IoT time series, real-time analytics, mobile apps, user profiles |
| 30 | |
| 31 | ### Choose PostgreSQL When: |
| 32 | - Strong consistency: ACID transactions critical |
| 33 | - Complex relationships: many-to-many joins, referential integrity |
| 34 | - SQL requirement: team expertise, reporting tools, BI systems |
| 35 | - Data integrity: strict schema validation, constraints |
| 36 | - Mature ecosystem: extensive tooling, extensions |
| 37 | - Complex queries: window functions, CTEs, analytical workloads |
| 38 | |
| 39 | **Best for:** Financial systems, e-commerce transactions, ERP, CRM, data warehousing, analytics |
| 40 | |
| 41 | ### Both Support: |
| 42 | - JSON/JSONB storage and querying |
| 43 | - Full-text search capabilities |
| 44 | - Geospatial queries and indexing |
| 45 | - Replication and high availability |
| 46 | - ACID transactions (MongoDB 4.0+) |
| 47 | - Strong security features |
| 48 | |
| 49 | ## Quick Start |
| 50 | |
| 51 | ### MongoDB Setup |
| 52 | |
| 53 | ```bash |
| 54 | # Atlas (Cloud) - Recommended |
| 55 | # 1. Sign up at mongodb.com/atlas |
| 56 | # 2. Create M0 free cluster |
| 57 | # 3. Get connection string |
| 58 | |
| 59 | # SECURITY WARNING: Never hardcode credentials in connection strings |
| 60 | # Use environment variables instead: |
| 61 | # mongodb+srv://${DB_USERNAME}:${DB_PASSWORD}@cluster.mongodb.net/db |
| 62 | # Or use connection string from MongoDB Atlas without embedding credentials |
| 63 | |
| 64 | # Connection (template - replace with env vars) |
| 65 | mongodb+srv://user:pass@cluster.mongodb.net/db |
| 66 | |
| 67 | # Shell |
| 68 | mongosh "mongodb+srv://cluster.mongodb.net/mydb" |
| 69 | |
| 70 | # Basic operations |
| 71 | db.users.insertOne({ name: "Alice", age: 30 }) |
| 72 | db.users.find({ age: { $gte: 18 } }) |
| 73 | db.users.updateOne({ name: "Alice" }, { $set: { age: 31 } }) |
| 74 | db.users.deleteOne({ name: "Alice" }) |
| 75 | ``` |
| 76 | |
| 77 | ### PostgreSQL Setup |
| 78 | |
| 79 | ```bash |
| 80 | # Ubuntu/Debian |
| 81 | sudo apt-get install postgresql postgresql-contrib |
| 82 | |
| 83 | # Start service |
| 84 | sudo systemctl start postgresql |
| 85 | |
| 86 | # Connect |
| 87 | psql -U postgres -d mydb |
| 88 | |
| 89 | # Basic operations |
| 90 | CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT, age INT); |
| 91 | INSERT INTO users (name, age) VALUES ('Alice', 30); |
| 92 | SELECT * FROM users WHERE age >= 18; |
| 93 | UPDATE users SET age = 31 WHERE name = 'Alice'; |
| 94 | DELETE FROM users WHERE name = 'Alice'; |
| 95 | ``` |
| 96 | |
| 97 | ## Common Operations |
| 98 | |
| 99 | ### Create/Insert |
| 100 | ```javascript |
| 101 | // MongoDB |
| 102 | db.users.insertOne({ name: "Bob", email: "bob@example.com" }) |
| 103 | db.users.insertMany([{ name: "Alice" }, { name: "Charlie" }]) |
| 104 | ``` |
| 105 | |
| 106 | ```sql |
| 107 | -- PostgreSQL |
| 108 | INSERT INTO users (name, email) VALUES ('Bob', 'bob@example.com'); |
| 109 | INSERT INTO users (name, email) VALUES ('Alice', NULL), ('Charlie', NULL); |
| 110 | ``` |
| 111 | |
| 112 | ### Read/Query |
| 113 | ```javascript |
| 114 | // MongoDB |
| 115 | db.users.find({ age: { $gte: 18 } }) |
| 116 | db.users.findOne({ email: "bob@example.com" }) |
| 117 | ``` |
| 118 | |
| 119 | ```sql |
| 120 | -- PostgreSQL |
| 121 | SELECT * FROM users WHERE age >= 18; |
| 122 | SELECT * FROM users WHERE email = 'bob@example.com' LIMIT 1; |
| 123 | ``` |
| 124 | |
| 125 | ### Update |
| 126 | ```javascript |
| 127 | // MongoDB |
| 128 | db.users.updateOne({ name: "Bob" }, { $set: { age: 25 } }) |
| 129 | db.users.updateMany({ status: "pending" }, { $set: { status: "active" } }) |
| 130 | ``` |
| 131 | |
| 132 | ```sql |
| 133 | -- PostgreSQL |
| 134 | UPDATE users SET age = 25 WHERE name = 'Bob'; |
| 135 | UPDATE users SET status = 'active' WHERE status = 'pending'; |
| 136 | ``` |
| 137 | |
| 138 | ### Delete |
| 139 | ```javascript |
| 140 | // MongoDB |
| 141 | db.users.deleteOne({ name: "Bob" }) |
| 142 | db.users.deleteMany({ status: "deleted" }) |
| 143 | ``` |
| 144 | |
| 145 | ```sql |
| 146 | -- PostgreSQL |
| 147 | DELETE FROM users WHERE name = 'Bob'; |
| 148 | DELETE FROM users WHERE status = 'deleted'; |
| 149 | ``` |
| 150 | |
| 151 | ### Indexing |
| 152 | ```javascript |
| 153 | // MongoDB |
| 154 | db.users.createIndex({ email: 1 }) |
| 155 | db.users.createIndex({ status: 1, createdAt: -1 }) |
| 156 | ``` |
| 157 | |
| 158 | ```sql |
| 159 | -- PostgreSQL |
| 160 | CREATE INDEX idx_users_email ON users(email); |