Python连接mongodb一般使用pymongo模块
1. pymongo模块的简单使用
# -*- coding:utf-8 -*-# Author: Wongduimport pymongo# 建立一个连接对象host = '10.0.0.60'port = 27017mongo_client = pymongo.MongoClient(host=host, port=port)# 连接指定数据库和表(如无,则创建)db_name = 'douban'db_table = 'Car_Numb'db = mongo_client[db_name]table = db[db_table]'''# 或者:db = mongo_client.db_nametable = db.db_table'''# 增加item = { 'id': 1, 'name': 'doubi', 'addr': '10.0.0.111'}table.insert(item)# 删除table.remove()# 查询results = table.find()for i in results: print(i)# 修改table.update()