RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
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文件。主要是通过正则匹配,可以自己测试,加以调整。

我们提供的服务有:网站制作、成都网站建设、微信公众号开发、网站优化、网站认证、磐石ssl等。为千余家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的磐石网站制作公司

#!/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

文章标题:mongodb批量查询库中表的统计信息
网站链接:http://cqwzjz.cn/article/psihhj.html