Skip to content
BENIBIX Learn

MongoDB

Development🗃️ DatabasesNoSQL Databases

Also known as Mongo

The top store for documents. Each record is a document, a lot like JSON.

Think of it like

Think of it like a box of folders. Each folder can hold a different mix of papers.

Example

Jack's game saves each player's profile and items as one MongoDB document. New item types need no schema change.

Why it matters

It is the document store you will most likely meet at work.

Definition

MongoDB is the most used document database. It stores each record as a document in a JSON-like format called BSON. Documents are grouped into collections. You query it with its own commands rather than SQL. It can spread data across many servers and keep copies for safety. Its server listens on port 27017 by default.

Example code

javascript
db.players.insertOne({ name: "Jack", level: 7, items: ["sword"] })
db.players.find({ level: { $gt: 5 } })
This saves one player, then finds each player above level 5.

Common mistake

Leaving it open to the internet with no password. Thousands of databases have been wiped or stolen this way.

Key takeaways

  1. 1
    Documents in collections. Like rows in tables.
  2. 2
    Its own query style. Commands, not SQL.
  3. 3
    Spreads out. Data across many servers.