- 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:
Room 7: Belal, Lina Abumahfood, Lujain Mansour, Noor Alrai
1. What is the difference between SQL and NoSQL?
SQL databases are relational, and NoSQL databases are non-relational. SQL databases use structured query language (SQL) and have a predefined schema. NoSQL databases have dynamic schemas for unstructured data. SQL databases are vertically scalable, while NoSQL databases are horizontally scalable
2. What is referencing and what is embedding in MongoDB?
There are two different ways to model relationships between data within the documents.
Referencing involves storing a link (usually an ID) to another document in a separate collection.
This is similar to foreign keys in relational databases.
Embedding involves storing the related data directly within the parent document as a sub-document.
This essentially nests the child's document within the parent.
3. Why should we embed more than referencing when we can in MongoDB?
Embedding is more efficient and clean than referencing. referencing is a heavier process and makes queries more demanding. also, embedding is preferred when data are regularly accessed together. Embedding is suitable when the related data is frequently accessed together and the embedded data does not grow without limit.
The more often a given workload can retrieve a single document and have all the data it needs, the more consistently high-performance your application will be.
4. When should we prefer referencing over nesting in MongoDB?
Referencing should be used more sparingly as there are limitations to referenced documents and references are less efficient. if a given document needs to be accessed from several different places then it may make make sense to make it a reference rather than embedded. Moreover, referencing is useful when the related data is accessed independently or when the embedded data can grow significantly.
5. What are ORMs? Why do we use them? Give an example of an SQL request with and without using ORM.
ORMs are tools used in software development to make working with databases easier. They allow us to interact with databases using objects instead of writing raw SQL queries. They simplify database operations and make code more maintainable. Example without ORM: "SELECT * FROM users WHERE age > 25." Example with ORM: "users = User.query.filter(User.age > 25).all()."
6. What is the difference between a table and a collection?