安装包
pip install pymongo
import pymongo
#连接
client=pymongo.MongoClient("mongodb://127.0.0.1:27017")
#数据库
db=client['xw']
#集合
col=db['test']
mydict={"name":"python"}
#插入数据
res=col.insert_one(mydict)
print(res)
# mylist=[
# {"name":"C++"},{"name":"Lua"}
# ]
# # res=col.insert_many(mylist)
# # print(res)
# for num,i in enumerate(mylist):
# i['id']=num
# col.insert_one(i)
## 查找数据
# res=col.find({},{"_id":0})
# for r in res:
# print(r)
#更新
col.update_one(mydict,{"$set":{"name":"python3"}})
#删除
col.delete_many({})