作者:冰点youth | 来源:互联网 | 2014-05-28 16:53
安装MongoDB$sudoapt-getinstallmongodb会自动安装libpcrecpp0libboost-system1.42.0libboost-filesystem1.42.0libboost-program-options1.42.0libboost-thread1.42.0xulrunner-2.
安装MongoDB
$sudo apt-get install mongodb
会自动安装libpcrecpp0 libboost-system1.42.0
libboost-filesystem1.42.0
libboost-program-options1.42.0 libboost-thread1.42.0
xulrunner-2.0-mozjs
mongodb-clients mongodb-server mongodb-dev mongodb 等依赖包。
$ps aux | grep mongod
安装Python语言驱动
$sudo apt-get install python-setuptools
$sudo easy_install pymongo
配置MongoDB
$sudo vim /etc/mongodb.conf
dbpath=’your datebase path’
logpath=’where to log’
logappend=true
bind_id=127.0.0.1
port=27017
mytestdb
创建Collection
进入数据库建立coolection数据库才算建立完成。使用
db.createCollection("mytestdb ", {capped:true, size:10000})
单位是kb
或者db.runCommand( {createCollection:" mytestdb ", capped:true,
size:100000} )
capped参数是建立固定大小的数据库文件,为了保证效率,mongo会在建立collection的时候占用磁盘空间,防止碎片。
> db.createCollection("mytestdb ", {capped:true,
size:10000})
> show collections
db.mytestdb.ensureIndex({age:-1})
使用Python测试
$python
>>> import pymongo
>>> cOnn=
pymongo.Connection(host="localhost",port=27017)
>>> db=conn.mytestdb
>>> for user in db.wfcoll.find({}):
... repr(user)