Developer and Text Tools

MongoDB and Redis for SQL Developers: Same Tasks, New Commands

Translate everyday SQL tasks into MongoDB and Redis commands, learn when each database fits, and avoid the admin commands that can wipe or block a server.

Saizul Amin
Saizul Amin30 Oct 2026 · 3 min read
MongoDB and Redis for SQL Developers: Same Tasks, New Commands

MongoDB and Redis for SQL Developers: Same Tasks, New Commands

If you learned databases through SQL, your first steps in MongoDB or Redis can feel like learning to write with the other hand. You know exactly what you want, an update, a count, a grouped total, but not how to say it. The free MongoDB and Redis Command Reference maps 45 everyday tasks across both systems, each next to the SQL you already know.

Two different tools

MongoDB and Redis are often grouped together as NoSQL, but they solve different problems.

MongoDB is a document database. Records are JSON-like documents that can contain nested objects and arrays, stored durably on disk. It has a rich query language, secondary indexes and an aggregation pipeline for grouping and transforming data. It is a general-purpose primary database.

Redis is an in-memory data structure server. Each key holds a string, hash, list, set, sorted set, stream or other structure, and commands operate on one key at a time with very low latency. It shines for caches, sessions, counters, rate limits, queues, leaderboards and real-time messaging. Many systems use a primary database for records and Redis beside it for speed.

Thinking in documents

In SQL you normalise data into tables and join them. In MongoDB you usually store data that is read together in one document: an order embeds its line items and delivery address. Queries use filter documents such as { age: { $gte: 18 } } instead of WHERE clauses, and updates use operators like $set, $inc and $addToSet. Joins exist through $lookup in the aggregation pipeline, but if you need them constantly, reconsider the document design.

Thinking in keys

Redis has no tables and no queries over values. You design key names, such as user:42 or rate:ip:203.0.113.5, and pick the structure that makes your operation a single command. A view counter is INCR. A leaderboard is a sorted set, updated with ZADD and read with ZREVRANGE. A job queue is a list with LPUSH and the blocking BRPOP. Finding records by another field means maintaining an extra set or hash yourself.

Expiry

Temporary data is where Redis excels: SET session:abc data EX 3600 stores a value that disappears after an hour, with no clean-up job. MongoDB offers TTL indexes that delete documents after a date field passes, checked roughly once a minute.

Aggregation

SQL's GROUP BY becomes MongoDB's $group stage, usually after a $match stage that filters first, just as WHERE comes before GROUP BY. In Redis you rarely aggregate on demand; instead you keep running totals with HINCRBYFLOAT or counters per day.

Commands to treat with care

  • KEYS * scans every key and blocks Redis while it runs; use SCAN with a cursor.
  • FLUSHALL and FLUSHDB delete everything without asking.
  • db.dropDatabase() removes a MongoDB database instantly.

Restrict these with access control lists and roles in production, and keep backups: mongodump for MongoDB and snapshot or append-only persistence for Redis.

Indexes still matter

NoSQL does not mean no tuning. A MongoDB query without a suitable index scans every document, just as a SQL query scans a table. Use explain to check that queries use an index, and create compound indexes in the order your queries filter and sort. In Redis, the key design is the index.

Step by step

  1. Search for a task in plain words, such as increment, expire or leaderboard.
  2. Filter by section if needed.
  3. Compare the MongoDB, Redis and SQL columns.
  4. Read warnings for admin commands.
  5. Try the command in mongosh or redis-cli on test data.

Privacy

The reference is static and runs in your browser; it never connects to your servers.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages