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设计】。

相关文章

pandas read_excel()和to_excel()函数解析

前言 数据分析时候,需要将数据进行加载和存储,本文主要介绍和excel的交互。 read_excel() 加载函数为read_excel(),其具体参数如下。 read_exce...

Python callable()函数用法实例分析

本文实例讲述了Python callable()函数用法。分享给大家供大家参考,具体如下: python中的内建函数callable( ) ,可以检查一个对象是否是可调用的 。 对于函数...

Python网页解析利器BeautifulSoup安装使用介绍

Python网页解析利器BeautifulSoup安装使用介绍

python解析网页,无出BeautifulSoup左右,此是序言 安装 BeautifulSoup4以后的安装需要用eazy_install,如果不需要最新的功能,安装版本3就够了,千...

python format 格式化输出方法

0、前言 在python2.7及以上的版本,str.format()的方式为格式化提供了非常大的便利。与之前的%型格式化字符串相比,他显得更为方便与优越。下面我们就来看看format的具...

解决python xlrd无法读取excel文件的问题

读取文件时报错: xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; fo...