Donate to support Ukraine's independence.

24 May'11

Installing MongoDB 1.8.1 on Ubuntu 11.04 and PyMongo

Install everything you need:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
sudo nano /etc/apt/sources.list

Next, add a line to sources.list:

  • on Ubuntu
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
  • on Debian
deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen
sudo apt-get update
sudo apt-get install mongodb-10gen
sudo apt-get install python-setuptools
sudo easy_install pymongo

Next, test the connection:

from pymongo.connection import Connection
from pymongo import ASCENDING
connection = Connection("localhost", 27017)
db = connection.test
db.my_collection.save({"x": 10})
db.my_collection.save({"x": 10, "y": "good"})
for item in db.my_collection.find …

Continue reading