- What is the difference between SQL and NoSQL?
- What is referencing and what is embedding in MongoDB?
- Why should we embed more than referencing when we can in MongoDB?
- When should we prefer referencing over nesting in MongoDB?
- What are ORMs? Why we use them? Give an example of an SQL request with and without using ORM.
- What is the difference between a table and a collection?
Some helpful resources:
Jana AbuHaltam, Raneem AlHamarneh, Mohamad Alchehabi, Hala Qitouqa
Q1
SQL are relational databases and NoSQL are non-relational databases
SQL databases are vertically scalable, NoSQL databases are horizontally scalable
SQL are table-based, NoSQL could be key-value pairs, document-based, graph databases or wide-column stores
Examples of SQL databases: Oracle, MySQL
Examples of noSQL databases: MongoDB and CouchDB
Q2 Embedded Documents:
Used for one-to-many relationships with a "contains" or "has a" association.
Example: Blog posts containing multiple comments. All comments are embedded within the blog post document.
Pros: Better performance for read and update operations as everything is in a single document.
Cons: Risk of data duplication and limited by the maximum document size of 16MB.
References (Manual References):
Used for many-to-many relationships and complex hierarchical data.
Example: Blog posts and comments stored in separate collections; comments reference the blog post’s _id.
Pros: Avoids data duplication and is effective for complex relationships.
Cons: Slower read performance due to the need for multiple queries to join related data.
Q3 Referencing saves space and allows for more scalability, but it can be slower due to multiple queries and can be complex to maintain data consistency. Choosing between them depends on your specific needs regarding performance, data size, and complexity.
Q4 use referencing when dealing with large, complex, frequently changing, or interrelated datasets where embedding would be impractical or inefficient.
Q5 1-Simplifies Code
2-Enhances Maintainability
3-Database Abstraction
4-Reduces Boilerplate
Without ORM (Using Raw SQL in Node.js):
the code in JS
Q6 table is structured collection of data organized in rows and columns
in collections, data is organized in documents