python连接mongodb密码认证实例

yipeiwu_com7年前Python基础

如下所示:

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()

以上这篇python连接mongodb密码认证实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python实现图片二值化及灰度处理方式

我就废话不多说了,直接上代码吧! 集成环境:win10 pycharm #!/usr/bin/env python3.5.2 # -*- coding: utf-8 -*- ''...

在Python中字符串、列表、元组、字典之间的相互转换

在Python中字符串、列表、元组、字典之间的相互转换

一、字符串(str) 字符串转换为列表 使用list()方法 str_1 = "1235" str_2 = 'zhangsan' str_3 = '''lisi''' tuple_1...

Linux中安装Python的交互式解释器IPython的教程

IPython是Python的交互式Shell,提供了代码自动补完,自动缩进,高亮显示,执行Shell命令等非常有用的特性。特别是它的代码补完功能,例如:在输入zlib.之后按下Tab键...

Python Deque 模块使用详解

创建Deque序列: from collections import deque d = deque() Deque提供了类似list的操作方法: d = deque(...

Pandas GroupBy对象 索引与迭代方法

如下所示: import pandas as pd df = pd.DataFrame({'性别' : ['男', '女', '男', '女', '男', '女',...