MongoDB: Documents Instead of Tables
| Introduction | |
| A scheme that doesn't exist | |
| When MongoDB When Not | |
| Indices and queries | |
| Backups and lines |
Introduction
MongoDB stores JSON-like documents in collections instead of lines in tables. Product catalog, user profile, event tape - everything in the relational database would spread out into five tables with Joinami, there's one document here.
A scheme that doesn't exist
No schema is freedom and trap at once: you can add fields without migration, but in a year five generations live in the collection. documents. Keep the schema in the code (app level validation) JSON Schema is in the database itself, or else flexibility will turn into archaeology.
When MongoDB When Not
Take for directories, content, and prototypes where the structure changes Faster than the migrations are written. Do not take for money and warehouse: where Transactions through multiple entities, more honest SQL. And for hot meters and cache on top of all this, keep it next to you. Redis.
Indices and queries
Without an index, MongoDB does COLLSCAN – a full collection scan. Index filter and sort fields, construct composite indices ESR (equality, sorting, range) The command explain() shows whether the query uses an index before the collection It will grow to millions.
Backups and lines
Production is a replica set of at least three nodes: primary accepts Record, secondary insure and give reading. Backups off. secondary via mongodump on schedule and check for recovery n In a sandbox, a dump that no one has deployed is hope, not hope. backup.
| Databases | |
| MongoDB | |
| NoSQL databases | |
| Redis |