In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to achieve replica collection and slicing in Mongodb. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
Python uses only mongo transactions
Using pymongo to manipulate databases in python
Import pymongomc = pymongo.MongoClient ('mongodb://localhost:27018', connect=False, maxPoolSize=2000) with mc.start_session () as session: with session.start_transaction (): mc [' test'] ['test']. Insert_one ({' test': 1}, session=session) mc ['test'] [' test']. Delete_one ({'averse: 1}, session=session).
But a mistake was reported in practical use.
MongoError: Transaction numbers are only allowed on a replica set member or mongos.
After searching the Internet, many of the solutions are to install a package for npm, and then use it to start mongo.
In fact, according to the meaning of English, I can almost understand what's going on. After searching the Internet, I found the root cause: the transaction only supports copy sets and slices. And my development environment is directly started by mongod.
Replica set
Replica set building
Start two mongodb services (one master and one slave)
# 1/usr/local/mongodb/mongodb4.0.10/bin/mongod\-bind_ip=0.0.0.0-port=27018--logpath=/var/log/mongodb/mongodb_4_0_10.log\-dbpath=/data/mongo_4.0.10_db\-replSet rs0-fork# 2/usr/local/mongodb/mongodb4.0.10/bin/mongod\-bind_ip=0.0.0.0-port=27019\-logpath=/var/log/mongodb/ Mongodb_4_0_10-2.log\-dbpath=/data/mongo_4.0.10_db-2\-replSet rs0-fork
Execute in mongo shell
# launch a new replica set rs.initiate () # add a replica set rs.add ("localhost.localdomain:27019") so much about how to implement replica sets and fragments in Mongodb. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can 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.