下载mongodb
启动mongodb服务
安装python包
python操作mongodb
from pymongo import * try: client = MongoClient('localhost', 27017) db = client.py3 col = db.t3 for index in range(10): col.insert_one({'name': 'py%s' % index}) print('ok') except Exception as e: print(e)
#coding:utf-8 # 倒包 from pymongo import MongoClient # 链接数据库实例 client = MongoClient('localhost',27017) # 选择一个数据库 # db = client.python3 db = client['python3'] # 选择一个集合 # col = db.test col = db['test'] # 查询 # temp = col.find() # print (type(temp)) # for i in temp: # print (i) # data = col.find_one() # print(data) # 插入数据 # for i in range(13): # key = str(i) # col.insert({key:i*i+1}) # 修改数据 # col.update({"12":145},{"$set":{"12":146}}) # 删除 col.remove({'12':146})