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

首頁 > 數據庫 > MongoDB > 正文

MongoDB服務端JavaScript腳本使用方法

2020-03-14 13:18:32
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了MongoDB服務端JavaScript腳本使用方法,需要的朋友可以參考下
 

常用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” 博客



注:相關教程知識閱讀請移步到MongoDB頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 禄劝| 浦东新区| 包头市| 泸水县| 松阳县| 吕梁市| 元氏县| 黄陵县| 江陵县| 新邵县| 芒康县| 天水市| 明溪县| 通山县| 红安县| 高邑县| 上蔡县| 区。| 云南省| 太保市| 宁陵县| 三亚市| 迁西县| 夏津县| 颍上县| 时尚| 乐都县| 民勤县| 南涧| 静安区| 大丰市| 商城县| 卓资县| 宁晋县| 大田县| 上犹县| 金湖县| 定陶县| 中超| 乐亭县| 绥滨县|