MongoDB Roadmap : MongoDB Basics
SQL vs NoSQL
SQL Databases
SQL (Structured Query Language) databases are also called relational databases.
- Have predefined schema.
- Data stored in tables with rows and columns.
- Follow ACID properties.
- Popular SQL databases: MySQL, PostgreSQL, Microsoft SQL Server.
Explanation:
- ACID:
- Atomicity means a transaction is all or nothing.This means that either all operations within the transaction are completed successfully, or none of them are. If any part of the transaction fails, the entire transaction is rolled back to its original state, ensuring data consistency and integrity.
- Consistency ensures data remains in a valid state.The database is in a consistent state both before and after the transaction is executed. Constraints, such as unique keys and foreign keys, must be maintained to ensure data consistency.
- Isolation means transactions are isolated from each other.multiple transactions can execute concurrently without interfering with each other. Each transaction must be isolated from other transactions until it is completed. This isolation prevents dirty reads, non-repeatable reads, and phantom read.
- Durability guarantees that once a transaction is committed, its changes are permanent and will survive any subsequent system failures. The transaction’s changes are saved to the database permanently, and even if the system crashes, the changes remain intact and can be recovered.
- MySQL: Widely used open-source relational database.
- PostgreSQL: Powerful open-source relational database with advanced features.
- Microsoft SQL Server: Proprietary relational database from Microsoft.
Advantages of SQL databases:
- Predefined schema: Ideal for applications with a fixed structure.
- ACID transactions: Ensures data consistency and reliability.
- Support for complex queries: Rich SQL queries can handle complex data relationships and aggregation operations.
- Scalability: Vertical scaling by adding more resources to the server (e.g., RAM, CPU).
The phrase "Scalability: Vertical scaling by adding more resources to the server" refers to a concept in computer science and information technology related to the ability of a system to grow and manage increased demand by enhancing its capabilities.
Vertical scaling, also known as scaling up, involves increasing the capacity of a single server by adding more hardware resources. This could include adding more CPU cores, increasing the amount of RAM, installing faster storage devices, or expanding the storage capacity. The goal is to make the server more powerful so it can handle more workload or a growing number of users.
In essence, the statement suggests that by adding more resources to a server, you can improve the scalability of a system. This is a common method to boost performance, especially in cloud services and data center management.
However, vertical scaling has its limitations, such as higher costs and the physical limits of how much you can expand a single server.
As a result, many modern systems also employ horizontal scaling, which involves adding more servers to distribute the load, to achieve greater scalability.
Limitations of SQL databases:
- Rigid schema: Data structure updates are time-consuming and can lead to downtime.
- Scaling: Difficulties in horizontal scaling and sharding of data across multiple servers.
- Not well-suited for hierarchical data: Requires multiple tables and JOINs to model tree-like structures.
The phrase "Not well-suited for hierarchical data: Requires multiple tables and JOINs to model tree-like structures" means that a particular system or technology is not ideal for dealing with data that has a hierarchical or tree-like structure.
In such systems, to represent data that has parent-child relationships or a nested structure, you would need to use multiple tables and perform JOIN operations to link these tables together. This indicates that the system is not efficient at handling hierarchical data because it cannot represent such structures directly within a single table and requires complex queries involving multiple tables to achieve the same.
NoSQL Databases
NoSQL databases: non-relational databases that don't follow a fixed schema.
Storage formats: JSON documents, key-value pairs, graphs.
Popular examples: MongoDB, Cassandra, Redis, Couchbase.
MongoDB: A document-oriented NoSQL database.
Cassandra: A distributed wide column store NoSQL database.
Redis: An in-memory data structure store used as a database, cache, and message broker.
Couchbase: A NoSQL document-oriented database.
Advantages of NoSQL databases:
- Flexible schema: Easily adapts to changes without disrupting the application.
- Scalability: Horizontal scaling by partitioning data across multiple servers (sharding).
- Fast: Designed for faster read and writes, often with a simpler query language.
- Handling large volumes of data: Better suited to managing big data and real-time applications.
- Support for various data structures: Different NoSQL databases cater to various needs, like document, graph, or key-value stores.
Limitations of NoSQL databases:
- Limited query capabilities: Some NoSQL databases lack complex query and aggregation support or use specific query languages.
- Weaker consistency: Many NoSQL databases follow the BASE (Basically Available, Soft state, Eventual consistency) properties that provide weaker consistency guarantees than ACID-compliant databases.
MongoDB: A NoSQL Database
This guide focuses on MongoDB, a popular NoSQL database that uses a document-based data model. MongoDB has been designed with flexibility, performance, and scalability in mind. With its JSON-like data format (BSON) and powerful querying capabilities, MongoDB is an excellent choice for modern applications dealing with diverse and large-scale data.
What is MongoDB
MongoDB is an open-source, document-based, and cross-platform NoSQL database that offers high performance, high availability, and easy scalability. It differs from traditional relational databases by utilizing a flexible, schema-less data model built on top of BSON (Binary JSON), allowing for non-structured data to be easily stored and queried.
Key Features of MongoDB
-
Document-oriented: MongoDB stores data in JSON-like documents (BSON format), meaning that the data model is very flexible and can adapt to real-world object representations easily.
-
Scalability: MongoDB offers automatic scaling, as it can be scaled horizontally by sharding (partitioning data across multiple servers) and vertically by adding storage capacity.
-
Indexing: To enhance query performance, MongoDB supports indexing on any attribute within a document.
-
Replication: MongoDB provides high availability through replica sets, which are primary and secondary nodes that maintain copies of the data.
-
Aggregation: MongoDB features a powerful aggregation framework to perform complex data operations, such as transformations, filtering, and sorting.
-
Support for ad hoc queries: MongoDB supports searching by field, range, and regular expression queries.
When to use MongoDB
MongoDB is a suitable choice for various applications, including:
-
Big Data: MongoDB’s flexible data model and horizontal scalability make it a great fit for managing large volumes of unstructured or semi-structured data.
-
Real-time analytics: MongoDB’s aggregation framework and indexing capabilities help analyze and process data in real-time.
-
Content management: With its dynamic schema, MongoDB can handle diverse content types, making it a suitable choice for content management systems.
-
Internet of Things (IoT) applications: MongoDB can capture and store data from a large number of devices and sensors, proving beneficial in IoT scenarios.
-
Mobile applications: MongoDB provides a flexible data model, which is an essential requirement for the dynamic nature and varying data types of mobile applications.
In conclusion, MongoDB is a powerful and versatile NoSQL database that can efficiently handle unstructured and semi-structured data, making it an excellent choice for various applications and industries.
What is MongoDB Atlas?
MongoDB Atlas is a fully managed cloud-based database service built and maintained by MongoDB. The Atlas platform is available on major cloud providers like AWS, Azure, and Google Cloud Platform, allowing developers to deploy, manage, and scale their MongoDB clusters in a seamless and efficient manner.
-
Database as a Service (DBaaS): MongoDB Atlas takes care of database-related operations like backups, monitoring, scaling, and security, allowing developers to focus on their application logic.
-
Global Cluster Support: Atlas enables the creation of globally distributed clusters. Data can be stored and replicated across multiple geographies for improved performance, high availability, and reduced latency.
-
Security: Atlas offers built-in security features, such as end-to-end encryption, role-based access control, and IP whitelisting. This ensures your data remains secure and compliant with industry standards.
-
Performance: MongoDB Atlas provides tools for monitoring and optimizing the performance of your database. Advanced features like performance advisor and index suggestions help keep your database running at optimal speed.
-
Easy Scaling: With Atlas, you can easily scale your cluster either vertically or horizontally, depending on your requirements. Atlas supports auto-scaling of both storage and compute resources.
-
Data Automation and Integration: Atlas allows seamless integration with other services, like BI tools and serverless functions. The platform also supports easy data migration from on-premises or cloud-based deployments.
To summarize, MongoDB Atlas is a powerful and versatile database service that simplifies and enhances the process of deploying, managing, and scaling MongoDB instances in the cloud. With its robust set of features and security capabilities, Atlas is an ideal choice for developers who want to build and maintain scalable and efficient applications using MongoDB.
MongoDB Terminology
This section of the guide will introduce you to the basic terminology used while working with MongoDB. Understanding these terms will help you to grasp the fundamentals of MongoDB and make it easier for you to follow along with the rest of the guide.
MongoDB Terminology
-
Database: A MongoDB database is used to store and manage a set of collections. It consists of various collections, indexes, and other essential data structures required to store the data efficiently.
-
Collection: A collection in MongoDB is a group of documents. The name of a collection must be unique within its database. Collections can be viewed as the table equivalencies in a relational database.
-
Document: A document is a record in a MongoDB collection. It is comprised of a set of fields, similar to a row in a relational database. However, unlike tables in a relational database, no schema or specific structure is enforced on the documents within a collection.
-
Field: A field in MongoDB is a key-value pair inside a document. It can store various types of data, including strings, numbers, arrays, and other documents. Fields in MongoDB can be seen as columns in a relational database.
-
Index: Indexes in MongoDB are data structures that improve the speed of common search operations. They store a small portion of the dataset in a well-organized structure. This structure allows MongoDB to search and sort documents faster by reducing the number of documents it has to scan.
-
Query: A query in MongoDB is used to retrieve data from the database. It retrieves specific documents or subsets of documents from a collection based on a given condition.
-
Cursor: A cursor is a pointer to the result set of a query. It allows developers to process individual documents from the result set in an efficient manner.
-
Aggregation: Aggregation in MongoDB is the process of summarizing and transforming the data stored in collections. It is used to run complex analytical operations on the dataset or create summary reports.
-
Replica Set: A replica set in MongoDB is a group of mongodb instances that maintain the same data set. It provides redundancy, high availability, and automatic failover in case the primary node becomes unreachable.
-
Sharding: Sharding is a method of distributing data across multiple machines. It is used in MongoDB to horizontally scale the database by partitioning the dataset into smaller, more manageable chunks called shards.
Reference:
原文地址:https://blog.csdn.net/2302_77608969/article/details/143358164
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!