- Check to see if pip is already installed
whereis pip
pip is a package management system used to install and manage software packages written in Python. - Install python-dev
sudo apt-get install build-essential python-dev
header files and a static library for Python - Install pip
sudo apt-get install python-pip - Install pymongo
sudo pip install pymongo
PyMongo is a Python distribution containing tools for working with MongoDB, and is the recommended way to work with MongoDB from Python
Simple Script
import datetime
import pprint
import pymongo
from pymongo import MongoClient
client = MongoClient('mongodb://localhost:27017/')
db = client.mydb
post = { "a" : datetime.datetime.utcnow() }
postId = db.test.insert(post);
find = db.test.find()
for item in db.test.find() :
pprint.pprint(item)
I've saved this script as "test.py" and it can be executed by typing
python test.py
in the terminal window.Successful output for me looks like:
craig@U14BASE01:~$ python test.py
{u'_id': ObjectId('54b8048557566138d66f7fa8'),
u'a': datetime.datetime(2015, 1, 15, 18, 18, 45, 239000)}
hi,this is excellent information..we provide by very easy learning good information.
ReplyDeleteMongoDB Training Centers in Chenai