dev.rean.me
database

Introduction to NoSQL Database

Learn what is NoSQL database, its 4 main types, and simple MongoDB example in very simple English, with easy tips for beginner.

2026-10-24 ยท 5 min read

Share:

Hello my friend! ๐Ÿƒ Today we learn about NoSQL database. Many big app like Facebook, Netflix, and Amazon use NoSQL. Let's see what it is!

1. What Is NoSQL?

NoSQL mean "Not Only SQL". It is database that not keep data in table with fixed row and column like MySQL or SQL Server.

NoSQL is more flexible. Each data can have different shape, no need same column for all.

Introduction to NoSQL Database

2. SQL vs NoSQL โ€” Quick Look

In SQL database, student data keep in table like this:

idnameagephone
1Sok20012345678
2Dara19NULL

Dara don't have phone, but column still there, so we must put NULL.

In NoSQL (document database), same data look like this:

{ "_id": 1, "name": "Sok", "age": 20, "phone": "012345678" }
{ "_id": 2, "name": "Dara", "age": 19 }

Dara just no have phone field. No problem! Each document can be different.

SQLNoSQL
Data store inTable (row and column)Document, key-value, column, or graph
StructureFixed (schema)Flexible
RelationshipStrong, use JOINUsually keep data together
ScaleAdd more power to one serverAdd more server easy
ExampleMySQL, SQL Server, PostgreSQLMongoDB, Redis, Cassandra, Neo4j

3. Four Main Types of NoSQL

3.1 Document Database

Keep data as document, look like JSON. Very popular type.

  • Example: MongoDB, CouchDB
  • Good for: Website, blog, user profile, product catalog
{
  "_id": 1,
  "name": "Sok",
  "skills": ["SQL", "Python"],
  "address": { "city": "Phnom Penh", "country": "Cambodia" }
}

See? One document can keep list (skills) and object inside object (address). In SQL, this need many table.

3.2 Key-Value Database

Very simple. Each data have one key and one value. Like dictionary.

  • Example: Redis, Amazon DynamoDB
  • Good for: Cache, login session, shopping cart
user:1:name    โ†’  "Sok"
user:1:cart    โ†’  ["book", "pen"]
session:abc123 โ†’  "logged_in"

Very very fast, because just find by key.

3.3 Column-Family Database

Keep data by column, not by row. Good for very big data.

  • Example: Apache Cassandra, HBase
  • Good for: Big data, log, data from sensor (IoT)

3.4 Graph Database

Keep data as node (thing) and edge (connection between thing).

  • Example: Neo4j
  • Good for: Social network, recommendation ("people you may know")
(Sok) --FRIEND_OF--> (Dara)
(Dara) --FRIEND_OF--> (Vuth)

Easy to find "friend of friend" with graph database.

4. Simple MongoDB Example

MongoDB is most popular NoSQL database. Let's try some basic command.

In MongoDB, collection is like table, document is like row.

Insert student:

db.students.insertMany([
  { name: "Sok", age: 20, class: "12A" },
  { name: "Dara", age: 19, class: "12B" },
  { name: "Vuth", age: 21, class: "12A", phone: "098765432" }
]);

Find all student:

db.students.find();

Find student in class 12A (same like WHERE class = '12A' in SQL):

db.students.find({ class: "12A" });

Update age of Sok:

db.students.updateOne({ name: "Sok" }, { $set: { age: 21 } });

Delete Dara:

db.students.deleteOne({ name: "Dara" });

Compare with SQL:

SQLMongoDB
DatabaseDatabase
TableCollection
RowDocument
ColumnField
SELECT * FROM studentsdb.students.find()
INSERT INTOinsertOne() / insertMany()
UPDATEupdateOne() / updateMany()
DELETEdeleteOne() / deleteMany()

5. When to Use NoSQL?

โœ… Use NoSQL when:

  • Data shape change often, or each data different.
  • You have very big data and many user.
  • You need very fast read and write.

โŒ Better use SQL when:

  • Data have many relationship (like bank, school, order system).
  • You need strong rule and data must always correct (transaction).
  • Structure of data is clear and not change much.

Tips

  • NoSQL is not better than SQL, and SQL is not better than NoSQL. Choose by your project need.
  • Learn SQL first. Then NoSQL become much more easy to understand.
  • For practice MongoDB, use free MongoDB Atlas (cloud) or install MongoDB Community on your computer.
  • Flexible don't mean messy! Still plan your document structure before start.
  • In document database, keep data that use together in same document. It make read faster.
  • Many real project use both: SQL for main data, Redis for cache. This is normal.

Conclusion

NoSQL is flexible database that not use fixed table. It have 4 main type: document, key-value, column-family, and graph. MongoDB is very good place to start. Understand both SQL and NoSQL make you strong developer. Keep learning my friend! ๐Ÿ’ก