In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
MongoDB server JavaScript script
Common JavaScript statements
Db.getSiblingDB () db.getCollectionNames () db.getCollection () db.printCollectionStats ()
Run the JavaScript script on mongo shell
Switch the database:
Use
Run the following script:
Var total = 0 index dbaStatCollections = function () {}; dbaStatCollections = function () {collNames = db.getCollectionNames (); for (var index = 0; index < index) {var coll = db.getCollection; var stats = coll.stats (); print ('ns,count,size,totalIndexSize'); print (stats.ns +','+ stats.count +','+ stats.size +','+ stats.totalIndexSize) }} dbaStatCollections ()
You can save the above script as dbaStatCollections.js
Run under linux shell
Mongo localhost:27017/ dbaStatCollections.js
Or run under mongo shell
Load ("dbaStatCollections.js")
Store JavaScript functions on the server
Db.system.js.remove ({"_ id": "dbaStatCollections"}); db.system.js.save ({_ id: "dbaStatCollections", value: function () {collNames = db.getCollectionNames (); for (var index = 0; index < collNames.length; index++) {var coll = db.getCollection); var stats = coll.stats () Print ('ns,count,size,totalIndexSize'); print (stats.ns +','+ stats.count +','+ stats.size +','+ stats.totalIndexSize);}); db.loadServerScripts (); dbaStatCollections ()
You can use this function in the current JavaScript context. After exiting the session, the function will not be saved. Can only be executed in Primary.
Note: the above output is saved as a CSV file to open.
Store the JavaScript function in the mongo shell startup configuration file .mongorc.js
Mongodb shell loads the ~ / .mongorc.js file by default, and you can customize the prompt variable to modify the shell prompt. You can also put the above commonly used DBA management functions here.
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.