mongo shell启动配置文件.mongorc.js(三)
发表于:2025-11-09 作者:千家信息网编辑
千家信息网最后更新 2025年11月09日,mongo shell启动配置文件.mongorc.js(三)自定义MongoDB操作函数可以把自己写的js代码保存在某个地方,让MongoDB加载它,然后就可以在MongoDB的命令行里操作它们。m
千家信息网最后更新 2025年11月09日mongo shell启动配置文件.mongorc.js(三)
mongo shell启动配置文件.mongorc.js(三)
自定义MongoDB操作函数
可以把自己写的js代码保存在某个地方,让MongoDB加载它,然后就可以在MongoDB的命令行里操作它们。
mongodb shell默认会加载~/.mongorc.js文件
例如以下修改了启动提示文字、左侧提示文字,增加了my_show_shards shell函数用于显示当前sharded collection的chunks在各分片的负载情况:
//~/.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()); }) }) }
文件
函数
文字
提示
配置
代码
命令
地方
情况
行里
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
清华数据库设计
网络安全知识竞赛成绩多久出来
原神亚服港澳台服务器
传奇数据库在那
组织开展网络安全宣传
生产线流程图软件开发
2022年网络安全工作总结
服务器带电清洗安全吗
药店医保数据和网络安全自查表
数据库在未来发展趋势
银行网络安全法宣讲ppt
服务器上的端口命令
软件开发职业探索
直接删除代理服务器怎么操作
vs与数据库连接
英伦大厦软件开发
数据库归档日志保留几天
网络安全自评估报告规范
数据库中判断死锁
长沙安强网络技术公司
网络安全应急联系人
中办发规范网络安全检查规范
河北固安网络安全检查
网络安全威胁的被动攻击
文件管理器启动服务器
网络技术qq群
网络安全等保是什么职位
湖北正规网络技术收费
怎样升级电视服务器
网络安全自评估报告规范