Database Tutorial #10: MongoDB Data Modeling

MongoDB’s flexible schema is a strength and a trap. You can store anything, but bad data modeling causes slow queries and bloated documents. Good modeling matches your access patterns. The Key Question: Embed or Reference? In SQL, you normalize data into separate tables and join them. In MongoDB, you have a choice: embed related data in the same document, or store it separately and reference it. Embed when: Data is always accessed together Child data belongs to only one parent The embedded data is bounded in size Reference when: ...

August 6, 2026 · 4 min

Database Tutorial #9: MongoDB Setup and CRUD

MongoDB stores data as documents — JSON-like objects with flexible structure. No fixed schema. No joins required for embedded data. This tutorial gets you up and running with MongoDB 8.0. Setup with Docker docker run -d \ --name mongodb \ -p 27017:27017 \ -e MONGO_INITDB_ROOT_USERNAME=admin \ -e MONGO_INITDB_ROOT_PASSWORD=password \ mongodb/mongodb-community-server:8.0-ubi8 Connect with mongosh: mongosh "mongodb://admin:password@localhost:27017" mongosh Basics // Show databases show dbs // Switch to (or create) a database use myapp // Show collections show collections // Create a collection explicitly (optional — auto-created on first insert) db.createCollection("users") Documents and Collections In MongoDB: ...

August 5, 2026 · 4 min

Claude Code Can Now Scan Your Code for Vulnerabilities

Anthropic shipped a Claude Security plugin for Claude Code. It runs a team of agents over your repository, hunts for vulnerabilities, and writes a report. “AI finds bugs in your code” is a claim you should be suspicious of. So instead of reading the announcement, I read the plugin’s source. The interesting part is not the scanning. It is that the plugin does not let its own model decide how much to trust the results. ...

August 5, 2026 · 7 min

Database Tutorial #8: PostgreSQL Replication and High Availability

A single database server is a single point of failure. If it goes down, your application goes down. Replication gives you a copy of your data on another server — for failover, for read scaling, and for backups. How Streaming Replication Works PostgreSQL primary-replica replication works through the Write-Ahead Log (WAL). Every change to the primary is recorded in WAL files. The replica connects to the primary, streams those WAL records, and replays them to stay in sync. ...

August 5, 2026 · 4 min

Database Tutorial #7: PostgreSQL Migrations and Schema Design

Your schema is the foundation of everything. Bad schema decisions are expensive to fix later. Good ones make your application easier to build and scale. Why Migrations? A migration is a versioned SQL file that changes your schema. Instead of running ALTER TABLE manually in production and hoping everyone does the same, migrations track every schema change in version control. Every team member applies the same migrations in the same order. Your CI pipeline applies them automatically. Rollbacks are possible. ...

August 5, 2026 · 6 min

Database Tutorial #6: PostgreSQL Transactions and Concurrency

Two users buy the last item in stock at the same time. Your app charges a card, then the payment service fails. A report runs while someone is editing data. These are concurrency problems. Transactions solve them. What is a Transaction? A transaction is a group of SQL statements that execute as one unit. Either all succeed or none apply. BEGIN; UPDATE accounts SET balance = balance - 100 WHERE id = 1; UPDATE accounts SET balance = balance + 100 WHERE id = 2; COMMIT; If anything fails between BEGIN and COMMIT, call ROLLBACK to undo everything: ...

August 4, 2026 · 6 min

Database Tutorial #5: PostgreSQL JSON and Full-Text Search

PostgreSQL is not just a relational database. It has first-class JSON support and a powerful full-text search engine built in. No separate search service needed for most applications. jsonb vs json PostgreSQL has two JSON types. Always use jsonb. json jsonb Storage Text, preserves whitespace Binary, compressed Indexing Not indexable GIN index supported Query speed Slow (re-parses on each read) Fast Key order Preserved Not preserved CREATE TABLE products ( id SERIAL PRIMARY KEY, name TEXT NOT NULL, metadata JSONB ); INSERT INTO products (name, metadata) VALUES ('Laptop', '{"brand": "Dell", "specs": {"ram": 16, "ssd": 512}, "tags": ["electronics", "work"]}'), ('Phone', '{"brand": "Apple", "specs": {"ram": 8, "ssd": 256}, "tags": ["electronics", "mobile"]}'); jsonb Query Operators -- -> returns a JSON value (keeps JSON type) SELECT metadata -> 'brand' FROM products; -- "Dell" -- ->> returns text SELECT metadata ->> 'brand' FROM products; -- Dell -- #> for nested paths (returns JSON) SELECT metadata #> '{specs, ram}' FROM products; -- 16 -- #>> for nested paths (returns text) SELECT metadata #>> '{specs, ram}' FROM products; -- 16 -- @> containment: does the left side contain the right? SELECT * FROM products WHERE metadata @> '{"brand": "Dell"}'; -- ? key exists SELECT * FROM products WHERE metadata ? 'brand'; -- ?| any of these keys exist SELECT * FROM products WHERE metadata ?| ARRAY['brand', 'price']; -- ?& all of these keys exist SELECT * FROM products WHERE metadata ?& ARRAY['brand', 'specs']; Updating jsonb -- Replace a key UPDATE products SET metadata = jsonb_set(metadata, '{brand}', '"Lenovo"') WHERE id = 1; -- Add a new key UPDATE products SET metadata = metadata || '{"price": 999}' WHERE id = 1; -- Remove a key UPDATE products SET metadata = metadata - 'price' WHERE id = 1; -- Update nested value UPDATE products SET metadata = jsonb_set(metadata, '{specs, ram}', '32') WHERE id = 1; Indexing jsonb A GIN index makes containment queries (@>) and key existence (?) fast: ...

August 4, 2026 · 5 min

OpenAI's Astra Solved 10 Open Math Problems. I Checked the Proofs.

On August 1, 2026, OpenAI said an internal version of its next model, Astra, solved ten open problems in mathematics and theoretical computer science. The tokens used to find the solutions would cost about $2,000 at API rates. Claims like this are usually impossible to check. This one is different. OpenAI published every proof as a Lean 4 certificate on GitHub. So I downloaded them and looked. ...

August 4, 2026 · 7 min

Database Tutorial #4: PostgreSQL Indexing and Performance

Your query works. But it is slow. The fix is almost always an index. This tutorial covers how indexes work in PostgreSQL, when to use them, and how to confirm they are actually helping. How a B-tree Index Works Without an index, PostgreSQL reads every row in the table to find matches. This is called a sequential scan. For a table with 10 million rows, that means 10 million comparisons. ...

August 4, 2026 · 5 min

Database Tutorial #3: PostgreSQL — Advanced Queries

Basic SELECT queries only get you so far. Real applications need joins, aggregations, and complex filtering. This tutorial covers the SQL features you will use every day. We assume you have PostgreSQL running. See PostgreSQL Setup and Basics if you need to set that up first. Sample Schema Let’s use a simple e-commerce schema for all examples: CREATE TABLE users ( id uuid DEFAULT gen_random_uuid() PRIMARY KEY, name text NOT NULL, email text UNIQUE NOT NULL, created_at timestamptz DEFAULT NOW() ); CREATE TABLE orders ( id uuid DEFAULT gen_random_uuid() PRIMARY KEY, user_id uuid REFERENCES users(id), status text NOT NULL DEFAULT 'pending', total decimal(10, 2) NOT NULL, created_at timestamptz DEFAULT NOW() ); CREATE TABLE order_items ( id uuid DEFAULT gen_random_uuid() PRIMARY KEY, order_id uuid REFERENCES orders(id), product text NOT NULL, quantity integer NOT NULL, price decimal(10, 2) NOT NULL ); JOINs JOINs combine rows from multiple tables based on a related column. ...

August 3, 2026 · 7 min