您的位置:首页 > 数据库 > Mongodb

python实践——批量统计mongodb数据库的集合大小

2015-12-16 19:55 633 查看
#!/usr/bin/env python
import os,sys
list = []
for i in range(3,50):
l = os.popen("/bin/echo 'show collections'| /usr/local/mongodb/mongodb/bin/mongo 127.0.0.1:27103/数据库名|sed -n '%sp'" %i)      #获取数据库的集合列表
l = l.read()
if l != "":
list.append(l)
else:
print "the collections is %s" %i
del list[i-4]
break
for i in list:
i = i.strip("\n")
os.popen("/bin/echo 'db.%s.stats()'| /usr/local/mongodb/mongodb/bin/mongo 127.0.0.1:27103/数据库名|sed -n '4p;6p;8p'>>mongodb_size_count.txt" %i)   #统计集合的大小并把结果写入mongodb_size_count.txt文件中
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mongodb 数据库 python