#这里用的是3.0.2 mongodb driver for python
#!/usr/bin/env python
import pymongo
import urllib
from pymongo import MongoClient
username="guest"
#password=urllib.quote_plus('sabc@defzg') # 3.0 以后的版本需对特殊字符进行处理,但在2.4版本这样不可以
password='sabc@defzg' #2.4版本需要这样才行,需保留特殊字符原样
client=MongoClient(host='127.0.0.1',port=27017,document_class=dict)
client.test.authenticate(username,password,source="test")
db=client.test
cl=db.table
result=cl.find({"key":"value"})
for item in result:
print item['source']
print item['email']
print '=---------------------------------='
client.close()
转载于:https://my.oschina.net/sskxyz/blog/423150