python中删除文档的方法

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)


微信扫描下方的二维码阅读更多精彩内容

python中删除文档的方法

每日分享到群里,或者推荐给朋友会得大量积分,机会可以兑换微信零钱红包,具体请点击这里,得到了微信红包可以用来支持大飞哥

大飞哥能不能加鸡腿就看各位了!

赞赏请扫

开发者微信

大飞哥微信

开发者微信反馈BUG或者VIP可以添加,其他情况反馈可能不及时,见谅

版权声明

初衷是提供高清手机电脑壁纸等图片素材免费分享下载,禁止商用。图片素材来源网络,版权归原作者所有,若有侵权问题敬请告知我们!

【友情提醒】:

因平台原因不易展示大尺度写真,有的写真展示越少代表此套写真越性感,特别是xiuren等写真每一套写真完整套图50-100张不等。更多内容的欣赏请移步 点击这里

【更多图集移步】: 每日更新-点击这里
漂亮小姐姐-点击这里
性感美女-点击这里
清纯女孩-点击这里
xiuren专栏-点击这里
整站资源下载-点击这里

相关新闻