温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

mongodb批量查询库中表的统计信息

发布时间:2020-06-19 06:31:40 来源:网络 阅读:613 作者:DB柠檬茶 栏目:MongoDB数据库
mongodb中,查看一个表的统计信息一般用:
db.t.stats()
主要信息有:  
"ns" : "gqtest.t",
"count" : 40001,      ###行数
"size" : 2188945,     ###数据大小单位字节
"storageSize" : 1126400,   
"totalIndexSize" : 1851392,  ###总索引大小
"indexSizes" : {
"_id_" : 753664,
"age_1_name_1" : 1097728
},
"avgObjSize" : 54.72225694357641,
"nindexes" : 2,            ###索引个数


提前将获取到的表名写入:college.txt文件。主要是通过正则匹配,可以自己测试,加以调整。

#!/bin/bash
user=admin
passwd=123456
database=gqtest
addres=/opt/mongodb3.2.13/bin/mongo
file=mongo_data.csv
for i in `cat college.txt`
    do
    college_name=`$addres --port 7211 -u$user -p$passwd --authenticationDatabase=admin $database  --eval "db.$i.stats()" |grep ns |awk 'NR==1{print $3}' `
    count=`$addres --port 7211 -u$user -p$passwd --authenticationDatabase=admin $database  --eval "db.$i.stats()" |grep count |awk 'NR==1{print $3}' `
    size=`$addres --port 7211 -u$user -p$passwd --authenticationDatabase=admin $database  --eval "db.$i.stats()" |grep size |awk 'NR==1{print $3}'`
    index_num=` $addres --port 7211 -u$user -p$passwd --authenticationDatabase=admin $database  --eval "db.$i.stats()" |grep nindexes |awk 'NR==1{print $3}' `
    indexsize=`$addres --port 7211 -u$user -p$passwd --authenticationDatabase=admin $database --eval "db.$i.stats()" |grep        totalIndexSize |awk 'NR==1{print $3}'`
echo -e  "$college_name    $count    $size $index_num $indexsize\n" >> $file
done
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI