這篇文章主要介紹“python中如何刪除文檔”,在日常操作中,相信很多人在python中如何刪除文檔問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”python中如何刪除文檔”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
創(chuàng)新互聯(lián)是一家專業(yè)提供鎮(zhèn)安企業(yè)網(wǎng)站建設(shè),專注與成都做網(wǎng)站、網(wǎng)站制作、H5場景定制、小程序制作等業(yè)務(wù)。10年已為鎮(zhèn)安眾多企業(yè)、政府機構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。
1、delete_one()方法刪除文檔。delete_one()需要一個查詢對象參數(shù)。它只刪除了第一次出現(xiàn)。
2、在刪除大量文檔時,使用delete_many方法,需要查詢對象。
如果我們向delete_many({})傳e_many({}),它將刪除集合中的所有文檔。
實例
# 讓我們 從 Flask 導(dǎo)入Flask import Flask , render_template import os # 導(dǎo)入操作系統(tǒng)模塊 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)
到此,關(guān)于“python中如何刪除文檔”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
文章名稱:python中如何刪除文檔
新聞來源:http://www.weahome.cn/article/jgjjdo.html