In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to achieve transaction management in MongoDB. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Background
Finally, we take a look at the transaction management of MongoDB, there is no this article, because most of the information on the Internet is too old, it is the previous version of MongoDB, it is true that there is no transaction management before the version of MongoDB 4.0, MongoDB released version 4.0, of which the most important sign is the introduction of transaction management.
Knowing the transaction management of MongoDB, let's try water, how to play with this transaction management.
How to play?
Let's first try in the normal single point mode, the steps are as follows, the transaction management is based on session. We can see that there is an error, saying that the transaction can only take effect in the replication set, not in single point mode.
Next, we will test under the replication set. We will not build the MongoDB replication set in windows. You can refer to what I wrote earlier. Here comes the portal. Let's start the environment first to test it.
01
The transaction was not committed:
First take a look at the data in coll_1 and coll_2, and the results are shown in the following figure.
We first open the session, and open the transaction, and then insert data into it. Notice that we did not commit the transaction. The following figure shows the step code and the result.
Now we look at the coll_1 and coll_2 tables and find that there is no new data.
02
Transaction commit:
Now let's add the commit transaction code to the previous code, which is as follows:
Let's check the data again to see if there is too much data.
03
Transaction rollback:
Transaction rollback is to change the statement that just committed the transaction to the statement of invalidating the transaction. The specific code is as follows.
Let's query the data, the data has not increased, perfect.
This is the end of the article on "how to achieve transaction management in MongoDB". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.