gpt4 book ai didi

python - 如何从 pymongo 发出 "show dbs"

转载 作者:IT老高 更新时间:2023-10-28 11:15:31 27 4
gpt4 key购买 nike

我正在使用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com