python 链接mongo数据库说明

December 09, 2023
测试
测试
测试
测试
1 分钟阅读

大家好,又见面了,我是你们的朋友全栈君。

1. 准备

1.1 安装python链接mongo的模块

pip install pymongo

2.实例代码

from pymongo import MongoClient

 # username:用户名,password:账号密码,localhost:数据库IP,dbname:数据库名
client = MongoClient("mongodb://username:password@localhost:27017/dbname")

# get db
db = client.get_default_database()

# get 数据库表名称:tableNames
collection = db.tableNames

# 数据查询
datas = collection.find({'field': "value"})

for data in datas:
   print(data)

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/149546.html原文链接:https://javaforall.cn

继续阅读

更多来自我们博客的帖子

如何安装 BuddyPress
由 测试 December 17, 2023
经过差不多一年的开发,BuddyPress 这个基于 WordPress Mu 的 SNS 插件正式版终于发布了。BuddyPress...
阅读更多
Filter如何工作
由 测试 December 17, 2023
在 web.xml...
阅读更多
如何理解CGAffineTransform
由 测试 December 17, 2023
CGAffineTransform A structure for holding an affine transformation matrix. ...
阅读更多