Databases
0/4 sections
0%

MongoDB

MongoDB is the leading document-oriented NoSQL database. It stores data as flexible JSON-like BSON documents, enabling rapid iteration on evolving schemas and powerful aggregation pipelines.

Relevant to My Experience

How this topic connects to real projects and companies

Experience

MongoDB in microservices and modern apps

Related Projects

1Documents & Collections

javascript
// MongoDB document structure
{
  "_id": ObjectId("64abc123"),
  "name": "Sufi Sulaiman",
  "email": "sufi@example.com",
  "role": "admin",
  "tags": ["engineer", "ai"],
  "address": {
    "city": "Toronto",
    "country": "Canada"
  },
  "orders": [
    { "id": "ord1", "total": 99.99, "date": ISODate("2024-01-15") }
  ],
  "createdAt": ISODate("2024-01-01T00:00:00Z")
}
javascript
// CRUD operations
const db = client.db('myapp');
const users = db.collection('users');

// Insert await users.insertOne({ name: "Alice", email: "alice@example.com" }); await users.insertMany([{ name: "Bob" }, { name: "Charlie" }]);

// Find await users.find({ role: "admin" }).sort({ createdAt: -1 }).limit(10).toArray(); await users.findOne({ email: "alice@example.com" });

// Update (no replace by default with $set) await users.updateOne({ _id: id }, { $set: { role: "admin" }, $push: { tags: "vip" } }); await users.updateMany({ role: "user" }, { $set: { active: true } });

// Delete await users.deleteOne({ _id: id }); await users.deleteMany({ active: false, createdAt: { $lt: cutoff } }); ```

2Queries & Aggregation

javascript
// Query operators
await users.find({
  age: { $gte: 18, $lt: 65 },
  tags: { $in: ["vip", "premium"] },
  "address.city": "Toronto",
  name: { $regex: /^sufi/i },
  deletedAt: { $exists: false },
}).toArray();

// Aggregation pipeline await orders.aggregate([ { $match: { status: "completed", createdAt: { $gte: startDate } } }, { $group: { _id: "$userId", totalSpent: { $sum: "$total" }, orderCount: { $sum: 1 }, avgOrderValue: { $avg: "$total" } }}, { $sort: { totalSpent: -1 } }, { $limit: 10 }, { $lookup: { // join with users collection from: "users", localField: "_id", foreignField: "_id", as: "user" }}, { $unwind: "$user" }, { $project: { name: "$user.name", totalSpent: 1, orderCount: 1 } } ]).toArray(); ```

3Indexes & Performance

javascript
// Single field index
await users.createIndex({ email: 1 }, { unique: true });

// Compound index (order matters leftmost prefix rule) await orders.createIndex({ userId: 1, createdAt: -1 });

// Partial index (only index matching documents) await users.createIndex({ email: 1 }, { partialFilterExpression: { active: true } });

// Text index for full-text search await products.createIndex({ name: "text", description: "text" }); await products.find({ $text: { $search: "wireless keyboard" } });

// Explain query plan await users.find({ email: "test@example.com" }).explain("executionStats");

// Mongoose schema with indexes const orderSchema = new mongoose.Schema({ userId: { type: ObjectId, ref: 'User', index: true }, status: { type: String, enum: ['pending','paid','shipped','delivered'] }, total: { type: Number, required: true }, createdAt: { type: Date, default: Date.now } }); orderSchema.index({ userId: 1, createdAt: -1 }); ```

4MongoDB Schema Design Patterns

javascript
// ── Embedded vs Referenced ────────────────────────────
// EMBED when: data is accessed together, child count is bounded
// REFERENCE when: data is large, accessed independently, unbounded

// Embedded (Blog post + comments) { _id: ObjectId("..."), title: "MongoDB Patterns", content: "...", comments: [ // embed accessed together, bounded { author: "Alice", text: "Great post!", date: ISODate("2024-01-15") }, { author: "Bob", text: "Very helpful!", date: ISODate("2024-01-16") } ] }

// Referenced (User + Orders orders are large and numerous) // users collection { _id: ObjectId("user1"), name: "Alice", email: "alice@example.com" }

// orders collection { _id: ObjectId("..."), userId: ObjectId("user1"), // reference total: 99.99, items: [{ sku: "abc", qty: 2, price: 49.99 }] }

// ── Bucket Pattern (time-series data) ───────────────── // Instead of one document per measurement → bucket by hour { sensor_id: "temp-01", hour: ISODate("2024-01-15T14:00:00Z"), // bucket key measurements: [ { minute: 0, value: 22.1 }, { minute: 1, value: 22.2 }, // ... 60 measurements ], nMeasurements: 60, minTemp: 21.8, maxTemp: 23.1 }

// ── Aggregation Pipeline ────────────────────────────── db.orders.aggregate([ { $match: { status: "completed", createdAt: { $gte: startDate } } }, { $unwind: "$items" }, { $group: { _id: "$items.sku", totalSold: { $sum: "$items.qty" }, totalRev: { $sum: { $multiply: ["$items.qty", "$items.price"] } } }}, { $sort: { totalRev: -1 } }, { $limit: 10 }, { $lookup: { from: "products", localField: "_id", foreignField: "sku", as: "product" }}, { $unwind: "$product" }, { $project: { _id: 0, name: "$product.name", totalSold: 1, totalRev: 1 }} ]); ```

Explore the Full Portfolio

This is the complete portfolio of Sufi Khan Sulaiman, a technology leader specialising in B2B commerce and digital automation. Start from the Home page for the overview, then move through two decades of career experience across FLIR Systems, Lorex Technology, and 1c Platform, and the full catalogue of project case studies spanning headless commerce migrations, AI recommendation engines, and multi-channel fulfilment systems.

The skills and certifications page maps the technical and leadership capabilities behind the work, while the articles and the knowledge base break down the thinking into actionable frameworks. For hands-on learning, the tutorials and applications sections cover practical builds from front-end fundamentals to full-stack web apps.

For consulting engagement, the expertise page outlines service offerings, the ecommerce hub covers platform architecture and automation strategy, and the ecommerce guide (PDF) is a downloadable 55-page field manual. When you are ready to talk, the contact page is the direct line.