国产探花免费观看_亚洲丰满少妇自慰呻吟_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頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 朝阳县| 永丰县| 顺平县| 射洪县| 赞皇县| 永兴县| 永康市| 河北区| 阿拉善右旗| 北安市| 罗平县| 临颍县| 西林县| 沾益县| 大同县| 嘉鱼县| 青神县| 宜春市| 大理市| 玉环县| 灯塔市| 柏乡县| 龙胜| 开远市| 陆丰市| 海口市| 隆尧县| 资兴市| 临汾市| 嘉祥县| 天长市| 梨树县| 南城县| 定结县| 涪陵区| 禹州市| 星子县| 巴塘县| 库尔勒市| 抚顺县| 沾益县|