Skip to content

Instantly share code, notes, and snippets.

@halitbatur
Created May 12, 2022 11:21
Show Gist options
  • Save halitbatur/94643c7ab95b676ff44eeb4375079ff6 to your computer and use it in GitHub Desktop.
Save halitbatur/94643c7ab95b676ff44eeb4375079ff6 to your computer and use it in GitHub Desktop.
Discussion about SQL vs noSQL

Discuss the answers for these questions with you teammates and write your answers in the comments.

  1. What is the difference between SQL and NoSQL?
  2. What is referencing and what is embedding in MongoDB?
  3. Why should we embed more than referencing when we can in MongoDB?
  4. When should we prefer referencing over nesting in MongoDB?
  5. What are ORMs? Why we use them? Give an example of an SQL request with and without using ORM.
  6. What is the difference between a table and a collection?

Some helpful resources:

@halakhellow
Copy link

@cbaksakal
Copy link

1. What is the difference between SQL and NoSQL?

  • SQL databases are relational, NoSQL databases are non-relational.
  • SQL databases use structured query language and have a predefined schema. NoSQL databases have dynamic schemas for unstructured data.
  • SQL databases are vertically scalable, while NoSQL databases are horizontally scalable.
  • SQL databases are table-based, while NoSQL databases are document, key-value, graph, or wide-column stores.
  • SQL databases are better for multi-row transactions, while NoSQL is better for unstructured data like documents or JSON.
  • NoSQL: MongoDB, Cassandra / SQL: MySQL, PostgreSQL

2. What is referencing and what is embedding in MongoDB?
Referencing means that the documents in a collection will be held separately. Therefore, the child document is going to have a reference to the parent document.

In embedding, parent document includes child documents in a nested manner. There will be no need to give a reference to the parent document.

3. Why should we embed more than referencing when we can in MongoDB?
Embedding is faster than referencing because we can read and update data in a single operation up to 16 mb. It is easier to use.
Generally used for one-to-many relations. "Has a", "contains" relation.

4. When should we prefer referencing over nesting in MongoDB?
If we have large files, a lot of child documents and we need fine control, we might use referencing. Referencing is also advantageous when we have many-to-many relationships.

5. What are ORMs? Why we use them? Give an example of an SQL request with and without using ORM.
ORMs -Object Relational Mappings- are simply libraries that make it easier to communicate with the databases. Normally, we are supposed to write full SQL queries as strings to communicate with the database. However, these SQL queries are time consuming and error-prone; even one typo would make our query fail. At that point, ORMs come to the rescue. Instead of typing queries by hand as a string, we use the commands of related language which behind the scenes uses SQL to communicate with the database.

6. What is the difference between a table and a collection?
Tables are used in SQL. Each row in a table has the same number of columns.

Collections are used in NoSQL. They are similar to the tables in SQL; however, each document in a collection can have a different number of columns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment