# 安装pymongo pip install pymongo
from pymongo import MongoClient
client = MongoClient("mongodb://username:password@localhost:27017/dbname") # username:用户名,password:账号密码,localhost:数据库IP,dbname:数据库名
db = client.get_default_database() # 获取数据库
collection = db.tableNames # 获取数据库表名称:tableNames
# 数据查询
datas = collection.find({'field': "value"})
for data in datas:
print(data)
mongodb与python交互
最新推荐文章于 2023-12-15 08:54:42 发布