In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Preface
MongoDB replica set creates local and admin databases by default. Local database mainly stores metadata of replica set, while admin database mainly stores MongoDB user, role and other information.
Mongodb gridfs automatically creates several indexes when inserting data at a time. The account in our program does not have createIndex permission. I need to create it manually. As a result, I forgot to execute use xxxdb to switch the database after connecting to the mongo server, so an index was created in the admin database. As a result, the program on the export side reported a lot of verification problems.
Mongo's admin database is so fragile that it just fails to create an index. To learn a lesson, never modify it manually in the future, let alone save data with admin.
Reflect on it, this operation mistake actually exposed some of my usual bad habits.
First, the connection mongo should specify the target data. I used to connect to admin and then use use to switch to the target database. It's hard to forget.
$# incorrect use of $mongo ourdomain.com/admin-u tom-p tompass$ # correct use of $mongo ourdomain.com/mydb-u tom-p tompass-authenticationDatabase admin
Second, if the createIndex is executed incorrectly in the admin database, the result returned clearly shows that the index was created successfully.
{"createdCollectionAutomatically": true, "numIndexesBefore": 1, "numIndexesAfter": 2, "ok": 1,...}
But I ignored it and continued to create indexes in the correct database. Otherwise, we can find the problem earlier.
Finally, index creation should be automated, such as gridfs, which creates indexes on md5 and filename.
Be cautious in using admin database
When the auth option is enabled in Mongod, users need to create a database account and authenticate it according to the account information during access, which is stored in the admin database.
Mongo-9551:PRIMARY > use adminswitched to db adminmongo-9551:PRIMARY > db.getCollectionNames () ["system.users", "system.version"] system.version stores version information of authSchema system.users stores database account information if users create custom roles, there will also be system.roles collections
Users can set up any collection and store any data under the admin database, but it is strongly recommended not to use the admin database to store application business data. It is best to create a new database.
MongoDB will cache the collected data of system.users and system.roles2 in the admin database in memory, so that user role information does not have to be loaded from disk every time of authentication. At present, the maintenance code of cache can work correctly only when the writes of system.users and system.roles are serialized. For more information, please see the official issue SERVER-16092.
We can see from the code that MongoDB will directly upgrade the intentional write lock (MODE_IX) on the admin database to the write lock (MODE_X), that is, the lock level of the write operation of the admin database can only reach the DB level, and it does not support multiple collection concurrent writes and concurrent reads when writing. If users store business data in an admin database, they may encounter performance problems.
If (supportsDocLocking () | | enableCollectionLocking) {if (supportsDocLocking () | | enableCollectionLocking) {+ / / The check for the admin db is to ensure direct writes to auth collections+ / / are serialized (see SERVER-16092). + if (_ id = = resourceIdAdminDB & &! isRead) {+ _ mode = MODE_X;+} + _ lockState- > lock (_ id, _ mode)
Summary
The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.
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.