python 扫描MongoDB数据库列表
Posted _雪辉_
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 扫描MongoDB数据库列表相关的知识,希望对你有一定的参考价值。
# coding: utf-8
import sys
from pymongo import MongoClient
from connect_db_forbatch import connect_mysql
# 同步mongodb信息
def sync_mongodb_infos():
tmp_dict = {}
mongodb_list = []
exclube_dbs = [\'__mongo_connector\', \'admin\', \'local\', \'config\', \'test\']
sql_clusters = "select host,ip from sbtest.ip;"
clusters = connect_mysql(\'127.0.0.1\').select_db(sql_clusters)
for cluster in clusters:
client = MongoClient(cluster[0], int(cluster[1]), username=\'dba\', password=\'970125\')
# 获取实例中所有库名
dbs = client.list_database_names()
for db in dbs:
if db not in exclube_dbs:
tmp_dict[\'name\'] = db
tmp_dict[\'ip\'] = cluster[0]
tmp_dict[\'port\'] = cluster[1]
mongodb_list.append(tmp_dict)
tmp_dict = {}
return
以上是关于python 扫描MongoDB数据库列表的主要内容,如果未能解决你的问题,请参考以下文章