python mongo
2.tar -zxvf pymongo-2.0.1.tar.gz
3.cd pymongo-2.0.1
4.python setup.py build
在此步,编译时可能出现的异常
--ImportError: No module named setuptools,这时你可以手工去下载setuptools来安装,在shell中执行如下命令(
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tarzxvfsetuptools-0.6c11.tar.gz
cdsetuptools-0.6c11
pythonsetup.pybuild
python setup.py install)
--Python.h: No such file or directory,系统默认的python包不是很全,这时,你需要sudo apt-get install python2.7-dev来安装,或者你可以通过aptitude search python|grep dev来查找你所需要的python
5.python setup.py install
pymongo用例:
例子如下:
#!/usr/bin/python #coding: utf-8 import pymongo #host:127.0.0.1 #port:27017 con = pymongo.Connection('127.0.0.1',27017) db = con.mydb db.add_user('test','test') db.authenticate('test','test') user=db.user user.drop() user.save({'id':1,'name':'pymongo'}) user.save({'id':2,'name':'python'}) datas=user.find() for data in datas: print data data=user.find_one() print data user.create_index('id') user.find().sort('id',pymongo.ASCENDING) user.find({'id':1}).count #user.remove({'id':1}) user.update({'id':2},{'$set':{'name':'kaka'}} #user.find_one({'id':1})
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16