python中如何删除文档
这篇文章主要介绍“python中如何删除文档”,在日常操作中,相信很多人在python中如何删除文档问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”python中如何删除文档”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
创新互联是一家专业提供镇安企业网站建设,专注与成都做网站、网站制作、H5场景定制、小程序制作等业务。10年已为镇安众多企业、政府机构等服务。创新互联专业网站建设公司优惠进行中。

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中如何删除文档”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!
网页标题:python中如何删除文档
转载来于:http://www.cqwzjz.cn/article/jgjjdo.html


咨询
建站咨询
