1、delete_one() 办法删除文档。delete_one() 须要一个查问对象参数。它只删除了第一次呈现。
2、在删除大量文档时,应用 delete_many 办法,须要查问对象。
如果咱们向 delete_many({}) 传 e_many({}),它将删除汇合中的所有文档。
实例
# 让咱们
从 Flask 导入 Flask import Flask , render_template
import os # 导入操作系统模块
import pymongo
MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
client = pymongo.MongoClient(MONGODB_URI)
db = client['thirty_days_of_python'] # accessing the database
query = {'name':'John'}
db.students.delete_one(query)
for student in db.students.find():
print(student)
# lets check the result if the age is modified
for student in db.students.find():
print(student)
app = Flask(__name__)
if __name__ == '__main__':
# for deployment we use the environ
# to make it work for both production and development
port = int(os.environ.get("PORT", 5000))
app.run(debug=True, host='0.0.0.0', port=port)
以上就是本次分享的全部内容,当初想要学习编程的小伙伴指路微信公众号 -Python 技术大本营,欢送各位的到来哦~