MongoDB: Documents Instead of Tables

Contents
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.

Related articles
Databases
MongoDB
NoSQL databases
Redis

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: