知行编程网知行编程网  2022-09-08 18:00 知行编程网 隐藏边栏  66 
文章评分 0 次,平均分 0.0
导语: 本文主要介绍了关于python中删除文档的方法的相关知识,包括python读取word文档,以及python list删除元素这些编程知识,希望对大家有参考作用。

如何在python中删除文档

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)


(推荐操作系统:windows7系统、Python 3.9.1,DELL G3电脑。)

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写
扫一扫二维码分享