首先需要导入的包



from bson import ObjectId


查询数据 通过collection名称wilson进行查询



wilson.find_one({‘_id’:ObjectId(‘5c2d3bf64ca2f1145726f386’)})


修改数据 通过collection名称wilson进行修改



wilson.update_one({‘_id’:ObjectId(‘5c2d3bf64ca2f1145726f386’),{"$set":{"a":100}}})


from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, String, Integer

engine = create_engine("mysql+pymysql://root:@172.17.0.1/apps_readers", encoding="utf-8", echo=True, max_overflow=5)
# 连接mysql数据库,echo为是否打印结果

Base = declarative_base() # 生成orm基类


class User(Base): # 继承生成的orm基类
__tablename__ = "sql_test" # 表名
id = Column(Integer, primary_key=True) # 设置主键
user_name = Column(String(32))
user_password = Column(String(64))


class Admin(Base):
__tablename__ = "admin"
id = Column(Integer, primary_key=True)
username = Column(String(32))
password = Column(String(64))


Base.metadata.create_all(engine) # 创建表结构
# 父类Base调用所有继承他的子类来创建表结构