In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Mongo shell startup configuration file .mongorc.js (3)
Custom MongoDB operation function
You can save your own js code somewhere, have MongoDB load it, and then manipulate it on the command line of MongoDB.
Mongodb shell loads the ~ / .mongorc.js file by default.
For example, the following changes are made to the startup prompt text and the left prompt text, and the my_show_shards shell function is added to display the load of the current sharded collection chunks in each shard:
/ / ~ / .mongorc.js / / show at begin var compliment = ["attractive", "intelligent", "like batman"]; var index = Math.floor (Math.random () * 3); print ("Hello, you're looking particularly" + compliment [index] + "today!"); / / change the prompt prompt = function () {if (typeof db = "undefined") {return "(nodb) >" } / / Check the last db operation try {db.runCommand ({getLastError: 1);} catch (e) {print (e);} return db + ">";} / / show all shard's chunks function my_show_shards () {var config_db = db.getSiblingDB ("config"); var collections = {} Var shards = {}; var shard_it = config_db.chunks.find (). Snapshot (); while (shard_it.hasNext ()) {next_item = shard_it.next (); collections [JSON.stringify (next_item ["ns"]). Replace (/\ "/ g,")] = 1 Shards [JSON.stringify (next_item ["shard"]). Replace (/\ "/ g,")] = 1;} var list_collections = []; var list_shards = []; for (item in collections) {list_collections.push (item);} for (item in shards) {list_shards.push (item) } list_collections.forEach (function (collec) {list_shards.forEach (function (item) {obj = {}; obj ["shard"] = item; obj ["ns"] = collec; it = config_db.chunks.find (obj) Print (collec, item, it.count ();})})}
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.