国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MongoDB > 正文

MongoDB服務端JavaScript腳本使用方法

2020-10-29 18:50:30
字體:
來源:轉載
供稿:網友

常用JavaScript語句

復制代碼 代碼如下:

db.getSiblingDB(<dbname>)  
db.getCollectionNames()   
db.getCollection(<collname>)   
db.printCollectionStats()

在mongo shell運行JavaScript腳本
 
切換數據庫:  

復制代碼 代碼如下:

use <dbname>

運行如下腳本:

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/<dbname> dbaStatCollections.js

或在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執行。

備注:以上輸出結果保存為CSV文件打開。
本文出自 “SQL Server Deep Dives” 博客

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 镇平县| 海阳市| 荆门市| 广宗县| 渑池县| 五大连池市| 安吉县| 永修县| 札达县| 正蓝旗| 文山县| 烟台市| 柘城县| 刚察县| 安龙县| 宝兴县| 秦皇岛市| 利辛县| 塔城市| 根河市| 台南市| 台南县| 长岛县| 鹤峰县| 九龙县| 宣化县| 亳州市| 巢湖市| 美姑县| 汾阳市| 沂南县| 孝昌县| 安仁县| 阳高县| 海口市| 镇江市| 高州市| 延长县| 公主岭市| 浪卡子县| 喀喇沁旗|