You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
auto/test/test_connent_mongo.py

21 lines
604 B

# -*- coding: utf-8 -*-
from pymongo import MongoClient
# 连接到MongoDB,这里假设MongoDB运行在默认端口上的本地机器
client = MongoClient('mongodb://root:aaaAAA111!!!@erhe.top:38000/')
# 获取数据库列表
db_list = client.list_database_names()
print("数据库列表:")
for db_name in db_list:
print(db_name)
# 获取指定数据库的集合列表
# db = client[db_name]
# collection_list = db.list_collection_names()
#
# print(f"\n数据库 '{db_name}' 的集合列表:")
# for collection_name in collection_list:
# print(collection_name)