Sikau

MongoDB · Day 14 · about 20 min

MongoDB in production

Replica sets, transactions, Atlas, and choosing SQL vs NoSQL.

Running it for real

Production MongoDB runs as a replica set (copies on several servers), backs itself up, and is usually hosted on MongoDB Atlas. And sometimes the right answer is: use PostgreSQL.

The essentials

  • Replica sets: one primary takes writes; secondaries copy it and take over if it fails.
  • Write concern / read preference trade safety and speed (e.g. w: "majority").
  • Transactions across documents exist (session.withTransaction) — but if you need them everywhere, your data may be relational.
  • Sharding splits huge collections across servers by a shard key.
  • Atlas: managed clusters, backups, monitoring, search and vector search.
  • Choose MongoDB for varied, nested, fast-changing document shapes; content, catalogues, events, prototypes.
  • Choose PostgreSQL for strongly related data, complex joins, strict integrity and transactions everywhere (it also has JSONB!).

The rest of this lesson

  • Write concern and read preferenceexplain
  • Multi-document transactionsexplain
  • Best fit?predict
  • Choose the settingmatch
  • Which database?match
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 15 lessons of MongoDB