1. 安装MongoDB
sudo apt-get install mongodb
如果能成功打印出MongoDB的版本信息,验证安装成功
mongo -version
开启/关闭MongoDB Service
service mongodb start service mongodb stop
显示Database
show dbs
使用某个Database,比如local
use local
显示该Database的Collections
show collections
2. 安装PyMongo
sudo apt-get install python-pip
pip install pymongo
3. 编写Python脚本,测试Mongo数据库
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from pymongo import MongoClient
conn = MongoClient('127.0.0.1',27017)
db = conn.mydb
my_set = db.test_set
my_set.insert({"name":"joe"})
for i in my_set.find():
print(i)