- 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:
mohmmad smadi , nour kayyali , hakeema alzaidanin , ahmad juma
1-SQL databases are relational, and NoSQL databases are non-relational
2-SQL databases use structured query language (SQL) and have a predefined schema. NoSQL databases have dynamic schemas for unstructured data
3-SQL databases are vertically scalable, while NoSQL databases are horizontally scalable.
Embedding: Stores related data directly within a single document, nesting it as subdocuments.
Referencing : Stores a reference (usually the _id field) to a related document in a separate collection.
Similar to foreign keys in relational databases.
Reduced Number of Queries, Faster Access to Data
The typical rule is:
What you use together, store together.
5)ORM (Object Relational Mapping) is a library that makes it easier to communicate with a database in code.
It is basically a technique to query or perform CRUD (Create, Read, Update, Delete) operations to the database, mainly RDBMS (Relational Databases), using an object-oriented paradigm. it makes CRUD operations faster.
ex: without using ORM :
const mysql = require("mysql");
const conn = mysql.createConnection({
host: "localhost",
user: "your_username",
password: "you_password",
database: "mydb",
});
conn.connect(function (error) {
if (error) {
console.log(error);
} else {
console.log("Connected!");
let sql = "INSERT INTO Users (username, password) VALUES ('john-doe', 'randompassword')";
conn.query(sql, function (error, result) {
if (error) {
console.log(error);
} else {
console.log(result);
}
});
}
});
with using ORM:
const Sequelize = require("sequelize");
const sequelize = new Sequelize("mydb1", "your_username", "your_password", {
dialect: "mysql",
});
//Defining User model
const User = sequelize.define("User", {
username: Sequelize.STRING,
password: Sequelize.STRING,
});
sequelize.sync();
User.create({
username: "john-doe",
password: "randompassword",
}).then(function (user) {
console.log(user);
});
collections is a group of documents , a document is like a table in relational database