- 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 4 - Members: Farah Alsoqi, Mahmoud Rumaneh, Najwan Shawareb, Mohammad Abdullah
Q1:
SQL databases are characterized by their relational nature and fixed schema, making them suitable for applications that demand structured data, complex queries, and well-defined relationships. These databases scale vertically, prioritizing ACID properties to ensure transaction reliability.
On the other hand, NoSQL databases are non-relational, providing flexibility in data models with dynamic or schema-less structures. They excel in horizontal scalability, making them ideal for scenarios involving rapidly changing data, high scalability requirements, and situations where a flexible schema is paramount. It's worth noting that NoSQL databases may trade off some ACID properties for enhanced performance.
The choice between SQL and NoSQL hinges on the specific needs of the application, leading to the adoption of a polyglot persistence approach in many modern systems, where both types are utilized to cater to diverse data management requirements.
Q2:
Embedded documents are stored as children inside a parent document. This means they are all stored under one collection, and whenever you retrieve the parent document, you also retrieve all its embedded documents.
In MongoDB, referencing entails structuring data into distinct collections or documents and forming relationships through references or foreign keys. This method supports normalized data structures, prioritizing data consistency; however, it necessitates additional queries for accessing related data when navigating through the established references.
Q3:
In MongoDB, choose embedding for small to medium-sized, frequently accessed data, providing better performance and simplified schema. Choose referencing for large, frequently updated data, ensuring consistency across documents. The decision depends on your specific use case, and many applications use a combination of both approaches.
Q4:
Often preferred when dealing with large or frequently updated data, when query flexibility and consistency are critical.
Q5:
ORMs (Object-Relational Mappers) bridge object-oriented programming and databases, simplifying database interactions. They abstract SQL complexities, enhance productivity, offer portability, align with the object-oriented paradigm, and improve security.
Example SQL Request without ORM:
SQL Code:
SELECT * FROM users WHERE age > 25;
Example SQL Request with ORM (using SQLAlchemy in Python):
Q6:
A table, integral to relational databases (RDBMS), serves as a structured storage unit where data is arranged in rows and columns, adhering to a fixed schema. In contrast, a collection, found in NoSQL databases, offers a storage unit that allows for flexible and dynamic data modeling, devoid of a predefined schema. Examples of these structures include tables in RDBMS like MySQL and collections in NoSQL databases like MongoDB.