python连接mongodb密码认证实例
作者:weisongming 时间:2022-09-02 07:08:21
如下所示:
from pymongo import MongoClient
#建立和数据库系统的连接,指定host及port参数
client = MongoClient('localhost', 27017)
#连接mydb数据库,账号密码认证
db = client.mydb
db.authenticate("account", "password")
#连接表
collection = db.myset
#查看全部表名称
db.collection_names()
print db.collection_names()
#访问表的数据,过滤查询
item = collection.find({},{"name":1,"age":21})
for rows in item:
print rows.values()
#访问表的一行数据
print collection.find_one()
来源:https://blog.csdn.net/weisongming/article/details/71425302
标签:python,mongodb
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
使用Python绘制图表大全总结
2022-08-09 20:35:27
![](https://img.aspxhome.com/file/2023/7/99517_0s.png)
高性能网站建设指南:性能提升的14个原则
2011-07-14 16:04:54
Python并发编程实例教程之线程的玩法
2022-02-02 08:17:41
用Python+OpenCV对比图像质量的几种方法
2022-06-28 10:57:59
![](https://img.aspxhome.com/file/2023/1/66821_0s.png)
mysql8.0主从复制搭建与配置方案
2024-01-15 11:26:25
![](https://img.aspxhome.com/file/2023/5/89925_0s.png)
解决MySql客户端秒退问题(找不到my.ini)
2024-01-20 15:36:52
![](https://img.aspxhome.com/file/2023/9/91449_0s.jpg)
微软雅黑的设计
2010-02-23 20:36:00
![](https://img.aspxhome.com/file/UploadPic/20102/23/01-83s.jpg)
Pytorch可视化的几种实现方法
2023-06-11 17:44:57
![](https://img.aspxhome.com/file/2023/0/69470_0s.gif)
又一款MVVM组件 构建自己的Vue组件(2)
2024-04-30 10:46:40
![](https://img.aspxhome.com/file/2023/9/130049_0s.png)
My Sql 1067错误与编码问题的解决方案
2024-01-19 12:53:53
![](https://img.aspxhome.com/file/2023/7/122897_0s.png)
网站中视觉元素的设计
2008-04-27 20:47:00
![](https://img.aspxhome.com/file/UploadPic/20084/27/2008427204953291s.jpg)
Python初学者必备的文件读写指南
2023-03-16 11:44:15
Python特征降维知识点总结
2022-07-12 11:17:42
微信小程序弹窗禁止页面滚动的实现代码
2024-02-25 17:28:21
![](https://img.aspxhome.com/file/2023/2/56362_0s.gif)
Python asyncio异步编程简单实现示例
2023-09-23 15:27:52
![](https://img.aspxhome.com/file/2023/9/68419_0s.jpg)
Python实现过迷宫小游戏示例详解
2022-02-07 06:21:52
![](https://img.aspxhome.com/file/2023/7/127157_0s.png)
浅谈node的事件机制
2024-05-05 09:22:03
![](https://img.aspxhome.com/file/2023/9/129339_0s.png)
Oracle 创建监控账户 提高工作效率
2009-10-14 11:47:00
![](https://img.aspxhome.com/file/UploadPic/200910/14/20091014121213816.jpg)
安装MySQL后include目录下没有找到libmysql.lib
2024-01-25 17:55:13
python把ipynb文件转换成pdf文件过程详解
2022-07-27 23:50:24
![](https://img.aspxhome.com/file/2023/1/84971_0s.png)