MongoDB VS RDBMS;MongoDB 4.0 & 4.4 transaction level.

MongoDB VS RDBMS

MongoDB is a NoSQL database, while RDBMS (Relational Database Management Systems) like MySQL and PostgreSQL are SQL databases. Here are some of the differences between MongoDB and RDBMS:
MongoDB VS RDBMS;MongoDB 4.0 & 4.4 transaction level._第1张图片

1、Data Model:

MongoDB uses a document-based data model, which means data is stored as documents in a collection. A document can have a flexible schema, and each document can have a different set of fields. On the other hand, RDBMS uses a table-based data model, where data is stored in tables with a fixed schema.

2、Scalability:

MongoDB is highly scalable, and it can handle large amounts of data and high traffic easily. It can be scaled horizontally across multiple servers, and it supports sharding out of the box. RDBMS, on the other hand, is vertically scalable, which means it can be scaled by adding more resources like RAM or CPU to the existing server.

3、Querying:

MongoDB provides a powerful query language that supports rich queries and aggregation functions. It also supports secondary indexes, which can be used to improve query performance. RDBMS also provides a powerful query language (SQL), but it is less flexible than MongoDB’s query language.

4、ACID Compliance:

RDBMS is designed to be ACID-compliant, which means transactions are guaranteed to be consistent and durable. MongoDB, on the other hand, sacrifices ACID compliance for performance and scalability. MongoDB provides atomicity and consistency at the document level, but not at the transaction level .

5、Schema flexibility:

MongoDB has a flexible schema, which means it allows for changes to the schema without downtime or migrations. This makes it easy to add or modify fields in documents. RDBMS, on the other hand, has a rigid schema, which means any changes to the schema require downtime and migrations.

Overall, MongoDB is well-suited for applications that require high scalability, flexible schemas, and high performance, while RDBMS is well-suited for applications that require strict data consistency and a well-defined schema.

MongoDB 4.0 transaction level.

In MongoDB 4.0, multi-document transactions were introduced, allowing developers to perform transactions across multiple documents, collections, and databases. These transactions are ACID-compliant, meaning they guarantee Atomicity, Consistency, Isolation, and Durability.

MongoDB 4.0 supports multi-document transactions at the session level. This means that a session must start a transaction explicitly by calling the startSession() and startTransaction() methods. The transaction can then be committed or aborted using the commitTransaction() or abortTransaction() methods, respectively.

The transaction level in MongoDB 4.0 is at the session level, which means that transactions are scoped to a single session. This allows for concurrent transactions to occur across multiple sessions, but not within the same session. Additionally, transactions can only be performed on replica sets or sharded clusters, and not on standalone MongoDB instances.

It’s important to note that not all operations in MongoDB support multi-document transactions, and some limitations apply. For example, MongoDB does not support distributed transactions that span multiple shards. However, transactions in MongoDB 4.0 are still a powerful feature that enables developers to perform complex operations and maintain data consistency across multiple documents and collections.

MongoDB 4.4 transaction level.

In MongoDB 4.4, the transaction level remains at the session level, as it was in MongoDB 4.0. However, MongoDB 4.4 introduced several improvements and new features related to transactions, such as retryable writes and support for read-only transactions.

Retryable writes allow MongoDB to automatically retry a failed write operation that may have failed due to a network error or other transient issue. This ensures that write operations are reliably completed and helps maintain the consistency of the database.

In addition, MongoDB 4.4 introduced support for read-only transactions, allowing developers to perform read operations within a transaction without requiring a write operation. This feature can improve performance and reduce contention for resources in certain use cases.

Another notable improvement in MongoDB 4.4 is the support for more granular locking at the collection level. This allows for better concurrency and scalability, especially when performing transactions across multiple collections.

It’s important to note that the transaction level in MongoDB 4.4 still applies to replica sets and sharded clusters, and not standalone MongoDB instances. In addition, not all operations support transactions, and some limitations still apply. However, the improvements and new features introduced in MongoDB 4.4 provide developers with more flexibility and scalability when working with transactions in MongoDB.

你可能感兴趣的:(MongoDB,mongodb,数据库)