我正在使用 pymongo,但我不知道如何执行相当于“show dbs”的 mongodb 交互式 shell。
最佳答案
from pymongo import MongoClient
# Assuming youre running mongod on 'localhost' with port 27017
c = MongoClient('localhost',27017)
c.database_names()
2020 年更新:
DeprecationWarning: database_names is deprecated
使用以下内容:
c.list_database_names()
关于python - 如何从 pymongo 发出 "show dbs",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11162551/