import pymongo
client = pymongo.MongoClient("127.0.0.1", port=27017)
db = client['py_test']
collection = db['name']
# 插入
# collection.insert({'age': 1})
# collection.insert_many([{'username': '1ni'}, {'username': '2ni'}])
# 查询 find_one 一条
data = collection.find({'age': 1})
for d in data:
print(d)
# 更新 update_many
# collection.update_one({'username': '1ni'}, {"$set": {'username': "2ni", "age": 222}})
# 删除
collection.delete_many({'age': '1'})