import pymongo,sys
from pymongo import MongoClient
client = MongoClient(host="localhost:27017",read_preference=pymongo.read_preferences.ReadPreference.PRIMARY_PREFERRED)
db = client.database
db.authenticate("database","passwd")
1.search
pi = db.locinfo.find({"con":p}) #search
pi = db.locinfo.find_one({"con":p})
print pi
{u'city': u'\u56fe\u6728\u8212\u514b\u5e02', u'wid': u'101130908', u'zip': u'843900', u'pro': u'\u65b0\u7586\u7ef4\u543e\u5c14\u81ea\u6cbb\u533a', u'wkey': u'\u56fe\u6728\u8212\u514b\u5e02', u'acode': u'0998', u'_id': u'txpcx5', u'fix': True, u'con': u'\u56fe\u6728\u8212\u514b\u5e02'}
2.update
db.locinfo.update({"con":p},{'$set':{"con":zc}}) # update one item
×××××××××××××××批量update ××× multi=True ××××××××××××××××××××××××××××××××
db.locinfo.update({"con":lon},{'$set':{"wkey": sht }},multi=True) #ok,# update multiple items
××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
3。insert # 插入数组,及一般字符窜
db.wbinfo.insert({"city":cityname,"jiaojing":[jiaojing],"lukuang":"lukuang,"})
4。push 、 pop 插入数组,删除数组元素
db.wbinfo.update({"city":"六安市"},{'$push':{"jiaojing":"two","lukuang":"lk"}})
db.wbinfo.update({"city":"六安市"},{'$pop':{"jiaojing":"two","lukuang":"lk"}})