本篇文章给大家分享的是有关MongoDB服务端中怎么使用JavaScript脚本,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

常用JavaScript语句
db.getSiblingDB(
db.getCollectionNames()
db.getCollection(
db.printCollectionStats()
在mongo shell运行JavaScript脚本
切换数据库:
use
运行如下脚本:
var total = 0;
var dbaStatCollections = function(){};
dbaStatCollections = function(){
collNames = db.getCollectionNames();
for (var index = 0; index < collNames.length; index++) {
var coll = db.getCollection(collNames[index]);
var stats = coll.stats();
print('ns,count,size,totalIndexSize');
print(stats.ns + ',' + stats.count + ',' + stats.size + ',' + stats.totalIndexSize);
}
}
dbaStatCollections();
可将上述脚本保存为dbaStatCollections.js,
在linux shell下运行
mongo localhost:27017/
或在mongo shell下运行
load("dbaStatCollections.js")
在服务端存储JavaScript函数
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(collNames[index]);
var stats = coll.stats();
print('ns,count,size,totalIndexSize');
print(stats.ns + ',' + stats.count + ',' + stats.size + ',' + stats.totalIndexSize);
}
}
}
);
db.loadServerScripts();
dbaStatCollections();
在当前JavaScript上下文中,可以使用该函数。退出该会话后,该函数不会被保存。只可在Primary执行。
以上就是MongoDB服务端中怎么使用JavaScript脚本,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联-成都网站建设公司行业资讯频道。
本文名称:MongoDB服务端中怎么使用JavaScript脚本-创新互联
当前链接:http://www.fbiktj.com/article/djddip.html
其他资讯
- 设备管理这八年——CSP和感慨-创新互联
- 包含安装macos系统要钱么的词条
- 关于碧桂园sap人力系统的信息
- c语言log函数怎么定义 c语言log函数用法
- c语言pow有多重载函数 c++有多个重载函数pow实例与参数列表匹配
- 【Python自动化Excel】Python与pandas字符串操作
- 怎么用mysql设计 mysql怎么做
- Linux基础命令:一步一深入探究(linux基础命令详解)
- 备案非本人机动车上传手持身份证照片怎么上传拍完为什么显示网络连接失败或超时这是什么原因?(昨天备案的时候因为身份证没在旁边所以拍不了然后今天就弄不了了)
- 碰到win10更新失败怎么解决


咨询
建站咨询
