Skip to content

Instantly share code, notes, and snippets.

@Kishimoto96
Created April 27, 2023 14:36
Show Gist options
  • Save Kishimoto96/1dcb8bddee9f84b77c7ef4d1bb5cd2fa to your computer and use it in GitHub Desktop.
Save Kishimoto96/1dcb8bddee9f84b77c7ef4d1bb5cd2fa to your computer and use it in GitHub Desktop.

Discussion about SQL and NoSQL:

  1. What is NoSQL?
  2. What is the difference between SQL and NoSQL databases, and when should you use one over the other?
  3. How do the data structures of SQL and NoSQL databases differ?
  4. What is MongoDB? and why we call it a document-oriented database?
  5. What are the most important MongoDB commands? explain two of them.
@Mustapha909
Copy link

Fatma Zehra Aydin, Rayan Alrouh, @sheidanouri, @Mustapha909

1-NoSQL can be defined as an approach to database designing, which holds a vast diversity of data such as key-value, multimedia, document, columnar, graph formats, external files, etc. NoSQL is purposefully developed for handling specific data models having flexible schemas to build modern applications.
NoSQL is famous for its high functionality, ease of development with a performance at scale. Because of such diverse data handling features, NoSQL is called a non-relational database. It does not follow the rules of Relational Database Management Systems (RDBMS), and hence does not use traditional SQL statements to query your data. Some famous examples are MongoDB, Neo4J, HyperGraphDB, etc.

2- The main difference between SQL and NoSQL databases is in their data modeling approach, with SQL databases using a structured, tabular data model and NoSQL databases using a more flexible, non-relational data model. SQL databases are ideal for applications that require complex querying and strict data consistency, while NoSQL databases are better suited for applications with rapidly changing data requirements, high data volume, and data that is unstructured or semi-structured. Choosing between SQL and NoSQL databases depends on the specific needs of the application and the trade-offs between consistency, scalability, and performance.

3- The five critical differences between SQL and NoSQL are:
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.
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

4- MongoDB is a popular open-source NoSQL document-oriented database that stores and manages data in flexible, JSON-like documents instead of tables with fixed schemas used in traditional relational databases. Each document can contain different types and amounts of data, and can be nested to form complex data structures. MongoDB uses a flexible data model that allows data to be stored in a way that reflects the structure of the application's objects or documents, making it easier and more natural to work with data. This is why MongoDB is called a document-oriented database, as it emphasizes storing data in documents rather than in tables with structured relationships.

5- 5. db.collection.find(): This command is used to retrieve documents from a collection in MongoDB. It takes an optional query parameter that can be used to filter the results based on specific criteria. For example, the command db.users.find({ age: { $gt: 25 } }) would retrieve all documents from the "users" collection where the "age" field is greater than 25. The find() command can also be used to specify which fields should be included or excluded from the results, and to sort the results based on specific criteria.

db.collection.updateOne(): This command is used to update a single document in a collection in MongoDB. It takes two parameters: a filter that identifies which document to update, and an update operation that specifies the changes to be made to the document. For example, the command db.users.updateOne({ name: "Alice" }, { $set: { age: 30 } }) would update the "age" field of the document in the "users" collection where the "name" field is "Alice" to be 30. The updateOne() command can also be used

@Ahmed
Copy link

Ahmed commented Apr 27, 2023 via email

@AmmarAlmuain
Copy link

@ahmadalashtar @masteroflune @khaled6120 @ahmad Ramin
1- NoSQL databases (aka "not only SQL") are non-tabular databases and store data differently than relational tables. NoSQL databases come in a variety of types based on their data model. The main types are document, key-value, wide-column, and graph. They provide flexible schemas and scale easily with large amounts of data and high user loads.
2- the main diff is the relationship between the db,When to use SQL databases:

You should use SQL databases when you need to store structured data.
You should use SQL databases when you need to perform complex queries on your data.
You should use SQL databases when you need to ensure the consistency of your data.

When to use NoSQL databases

You should use NoSQL databases when you need to store large amounts of unstructured or semi-structured data.
You should use NoSQL databases when you need to store data that is constantly changing.
You should use NoSQL databases when you need to scale your database quickly.

3- noSQL is stored as document "key:value" pairs
SQL is stored in tables columns and rows
4- MongoDB is a document-oriented NoSQL database used for high volume data storage. Instead of using tables and rows as in the traditional relational databases, MongoDB makes use of collections and documents. Documents consist of key-value pairs which are the basic unit of data in MongoDB.
5- use - This command is used to select a database.
db - This command is used to get the current database.
show collections - This command is used to list all of the collections in the current database.
insertOne() - This command is used to insert a single document into a collection.
find() - This command is used to find documents in a collection.

@abdulrahmanalbakkar
Copy link

abdulrahmanalbakkar commented Apr 27, 2023

  1. Abdulrahman Albakkar 2. Cansu Aysagdic 3. Zakarie Ali 4. Hisham Al-Wattar

Q1.
NoSQL databases (aka "not only SQL") are non-tabular databases and store data differently than relational tables. NoSQL databases come in a variety of types based on their data model. The main types are document, key-value, wide-column, and graph. They provide flexible schemas and scale easily with large amounts of data and high user loads.

Q2.
An SQL, or relational database, is excellent for data processing—creating granular connections between pieces of data. A NoSQL database is great for finding one piece of data quickly and operating on it. There's little to no searching; it just gives you the user data.

Q3.
SQL databases are relational, and NoSQL databases are non-relational.
SQL databases are table-based, while NoSQL databases are document, key-value, graph, or wide-column stores.

Q4.
Instead of storing data in fixed rows and columns, document databases use flexible documents. Document databases are the most popular alternative to tabular, relational databases.
A document is a record in a document database. A document typically stores information about one object and any of its related metadata.
Documents store data in field-value pairs. The values can be a variety of types and structures, including strings, numbers, dates, arrays, or objects. Documents can be stored in formats like JSON, BSON, and XML.

To run a command against the current database, use db.runCommand():
db.runCommand( { } )
To run an administrative command against the admin database, use db.adminCommand():
db.adminCommand( { } )
Show dbs:
displays a list of all databases on the MongoDB server.
db.createCollection(""):
creates a new collection in the current database.

@saidbaradai
Copy link

@nourkrimesh @TasneemAkkad @mohamadAid

1-NoSQL is a type of database that can handle large volumes of unstructured data and does not rely on a fixed schema or SQL for querying and managing data. It's often used in web applications for its scalability, performance, and flexibility.

2-SQL databases are relational databases with a fixed structure that enforce strict data consistency, while NoSQL databases are non-relational databases with a flexible structure that prioritize scalability and speed. The choice between SQL and NoSQL depends on the specific requirements of your application and the type of data you need to store and manage.

  1. SQL databases use a tabular structure with pre-defined columns and rows, while NoSQL databases use a variety of flexible data structures such as key-value, document-based, column-family, and graph-based structures to store data. NoSQL databases can handle unstructured and semi-structured data more efficiently than SQL databases.

  2. MongoDB is a popular, flexible, and scalable database platform that is designed to handle large amounts of unstructured or semi-structured data.
    MongoDB is often referred to as a document-oriented database because it stores information in a document format rather than in tables, rows, or columns as in traditional relational databases.

  3. Some of the most important MongoDB commands are db.collection.find(), db.collection.insertOne(), and db.collection.updateOne().
    db.collection.find() is used to retrieve documents that match a query and project the desired fields. db.collection.insertOne() is used to insert a new document into a collection, and db.collection.updateOne() is used to update a single document in a collection that matches a filter.

@sncey
Copy link

sncey commented Apr 27, 2023

@ilaydanurguzel1 @jimaa-maya @tomiece317 @mustafakraizim98 @MuhammedMustafaAlnaddaf1

1- NoSQL (Not Only SQL) is a type of database management system that does not use the traditional SQL relational database model. Instead, NoSQL databases use a flexible and scalable data model, typically using document-oriented, key-value, graph, or column-family database architectures. NoSQL databases are often used for handling large amounts of unstructured or semi-structured data, which can be challenging to manage in a traditional SQL database.

2- SQL databases use structured tables and predefined schemas to store data, while NoSQL databases use flexible data models that can handle various types of data structures. SQL databases are best for applications that require complex querying and have structured data, while NoSQL databases are ideal for applications that need to handle large volumes of rapidly changing and unstructured data. Ultimately, the choice between SQL and NoSQL databases depends on the specific requirements of the application and the type of data that needs to be stored and retrieved. SQL databases are best used for structured data, NoSQL databases are suitable for structured, semi-structured, and unstructured data.

3- SQL databases use a structured, table-based data model with strict data consistency rules, while NoSQL databases use flexible, non-tabular data models that can handle unstructured or semi-structured data without strict data consistency rules. NoSQL databases typically use documents, key-value pairs, graphs, or column families to store data, and they often have a distributed architecture for scalability and high availability.

4- MongoDB is an open-source document-oriented database that is designed to store a large scale of data and also allows you to work with that data very efficiently. It is categorized under the NoSQL (Not only SQL) database because the storage and retrieval of data in the MongoDB are not in the form of tables. Because it handles information as if it were a structured document.
As opposed to a key-value store where the internals of a document are not visible to the database or accessible. In those cases the record must be consumed by the application for processing. Or a column family where parts of the document are placed into columns for access by the database.
MongoDB on the other hand allows indexing and updates within the JSON document that is stored in the db. So each part of the document is accessible to the database.

5- Two important MongoDB commands are db.collection.find(), which is used to query data from a MongoDB collection based on filter criteria, sorting instructions, and projection fields, and db.collection.insertOne(), which is used to insert a single document into a MongoDB collection with the specified data. db.mycol.help()": If you need help using a collection, then you use this command. Example, db.mycol.help().

@motaz99
Copy link

motaz99 commented Apr 27, 2023

Rasam, Asli, Baraah, Motaz

  1. NoSQL databases are non-relational databases. They have roughly the same characteristics as SQL databases (durable, resilient, persistent, replicated, distributed, and performant) except for the major difference of not enforcing schemas (or enforcing only very loose schemas). These databases provide flexible schemas and scale easily with large amounts of data and high user loads.

  2. SQL uses tables and creates relations between data, NoSQL uses documents and most probably doesn't have relations between data. NoSQL databases is better with the huge applications because it is more flexible and cheap for add new features, it are also good with frequent data changes, SQL is slower but still reliable on huge apps, it has fixed data, it is expensive to grow up.

  3. In SQL they use tables to store data and they create relations between tables, NoSQL databases (aka "not only SQL") are non-tabular databases and store data differently than relational tables. NoSQL databases come in a variety of types based on their data model. The main types are document, key-value, wide-column, and graph.

  4. MongoDB is a popular open-source NoSQL database that is designed to store and manage unstructured and semi-structured data. It is a document-oriented database that stores data in flexible and scalable JSON-like documents, which are known as BSON (Binary JSON) documents. MongoDB a document-oriented database because it focuses on storing and managing data as self-contained documents instead of using traditional relational database tables with rows and columns

    1. db.collection.insertOne(): This command is used to insert a single document into a collection in MongoDB
    2. db.collection.find(): This command is used to retrieve documents from a collection in MongoDB. It can be used to find all
      documents in a collection or to find documents that match a specific condition

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