iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >mongodb批量查询库中表的统计信息
  • 446
分享到

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

2024-04-02 19:04:59 446人浏览 泡泡鱼
摘要

在mongoDB中,查看一个表的统计信息一般用: db.t.stats() 主要信息有: "ns" : "gQtest.t", "count" : 40001, ###行数 "size" :

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
您可能感兴趣的文档:

--结束END--

本文标题: mongodb批量查询库中表的统计信息

本文链接: https://www.lsjlt.com/news/37721.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作