1. MongoDB安装
安装
sudo apt-get install mongodb
查看是否安装成功,查看版本
mongo -version
service mongodb start service mongodb stop
mongo启动shell模式
mongo
2. python调用mongo的驱动安装
安装pip服务
sudo apt install python-pip
安装pymongo驱动
pip install pymongo
更新pymongo驱动
@H_502_47@pip @H_502_47@install --@H_502_47@upgrade @H_502_47@pip
3. 测试
pymongo_test.py
@H_502_47@#!/usr/bin/env python
@H_502_47@# -*- 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":"joe001","age":3})
my_set.insert({"name":"joe002","age":4})
my_set.insert({"name":"joe003","age":5})
for i in my_set.find():
print(i)
参考
http://www.jb51.cc/article/p-tsxrjyfh-bbo.html
https://www.cnblogs.com/melonjiang/p/6536876.html