NoSQL is a non-relational Data Management System
Example:
Previously, We only use SQL to store data and query if we need. However, today, when science and technology are more developed so data is so big, therefore when we need to query db so very slow.
Example: You develop Ecommerce website. Every day, the data becomes larger as: product, order, user table ......1 billion rows and you can't select data to view. Therefore NoSQL is born
SQL NoSQL
SQL NoSQL
RDMS: Relationship Database Management System
Non-RDMS: Non Relationship Database Management System
When you use RDMS to store(insert) data so all records will be stored into ONE table => ONE file in that server
When you use Non-RDMS to store(insert) data so each record will be stored into EACH Shard => EACH file in EACH server
=> Which Shard/File/Server? that is for the router to decide.
Routers(Mongos)
Config Server Replica Sets
Shards
Routers(Mongos) will sends the query request to all shards to check which shard has the data. Once it receives the response from all shards it sends the result to the client application
The methods such as updateMany() and deleteMany() triggers the Broadcast Operations
Routers(Mongos) instances use the shard key value to determinate the chunk of data. As above id=1.000.010 in Shard2, and router will point cursor to shard 2 to query data
The oeration such as insertOne(), updateOne(), deleteOne()
With above image you will have three tables: user, order && product and need to know: "How many orders does the user order?
Query:
SELECT *
FROM user AS u
JOIN order AS o
ON u.id = o.user_id
JOIN product AS p
ON o.product_id = p.id
WHERE u.name like '%dang%';
Analyze the query above
user table: 2 rows
order table: 2 rows
product table: 3 rows
=> Total rows need to query: 2 x 2 x 3 = 12 rows
With above image you will have three tables: user, order && product and need to know: "How many orders does the user order?
Query:
db.order.find({"user.name": /dang/});
Analyze the query above
order table: 1 row
=> Total row(s) need to query: 1