這篇文章主要介紹“python中如何刪除文檔”,在日常操作中,相信很多人在python中如何刪除文檔問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”python中如何刪除文檔”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
創(chuàng)新互聯(lián)是一家專(zhuān)業(yè)提供鎮(zhèn)安企業(yè)網(wǎng)站建設(shè),專(zhuān)注與成都做網(wǎng)站、網(wǎng)站制作、H5場(chǎng)景定制、小程序制作等業(yè)務(wù)。10年已為鎮(zhèn)安眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專(zhuān)業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。

1、delete_one()方法刪除文檔。delete_one()需要一個(gè)查詢對(duì)象參數(shù)。它只刪除了第一次出現(xiàn)。
2、在刪除大量文檔時(shí),使用delete_many方法,需要查詢對(duì)象。
如果我們向delete_many({})傳e_many({}),它將刪除集合中的所有文檔。
實(shí)例
# 讓我們
從 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é)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
網(wǎng)頁(yè)名稱:python中如何刪除文檔
網(wǎng)站URL:http://chinadenli.net/article10/jgjjdo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、手機(jī)網(wǎng)站建設(shè)、微信公眾號(hào)、網(wǎng)站導(dǎo)航、網(wǎng)站維護(hù)、App設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)