Simple introduction to MongoDB
Install MongoDB $ sudo apt-get install mongodb Will automatically install 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 and other dependent packages. $ps aux | grep mongod Install the Python language driver $ sudo apt-get install python-setuptools $ sudo easy_install pymongo Configure 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 Create Collection Entering the database to create a coolection database is considered complete. use db.createCollection(“mytestdb “, {capped:true, size:10000}) The unit is kb Or db.runCommand({createCollection:” mytestdb “, capped:true, size:100000} ) The capped parameter is to create a fixed-size database file. To ensure efficiency, mongo will occupy disk space when creating a collection to prevent fragmentation. > db.createCollection(“mytestdb”, {capped:true, size:10000}) > show collections db.mytestdb.ensureIndex({age:-1}) Testing with Python $python >>> import pymongo >>> cOnn= pymongo.Connection(host=”localhost”, port=27017) >>> db=conn.mytestdb >>> for user in db.wfcoll.find({}): …repr(user)