常用数据库:MongoDB

简单实例:

import pymongo  # 官方文档:https://api.mongodb.com/python/current/index.html
# 【连接MongoDB】
client = pymongo.MongoClient(host='localhost',port=27017)  # port默认参数为27017
# 【指定数据库】
db = client.test  # MongoDB 中默认的数据库为 test,如果你没有创建新的数据库,集合将存放在 test 数据库中
# 【指定Collection】
collection = db.students
# 【插入数据】
student = {
    'id': '123012015058',
    'name': 'handsome hj',
    'age': 23,
    'gender': 'male'
}
result = collection.insert_one(student).inserted_id
print(type(result), result)  # 注意_id并不是一个字符串
print(collection.find_one())  # 查询一个
print(collection.find_one({'name': 'handsome hj'}))  # 带值查询
result = collection.find({'name': 'handsome hj'})  # 查询多个,返回值为生成器
for i in result:
    print(i)
collection.delete_many({'name': 'handsome hj'})  # 删除操作

# 【更多Collection层面的操作请查阅:https://api.mongodb.com/python/current/api/pymongo/collection.html】
原文地址:https://www.cnblogs.com/lokvahkoor/p/10763405.html