In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.