刪除文件

Python 中的 MongoDB 入門

Filip Schouwenaars

Machine Learning Researcher

刪除單一文件

# Setup
from pymongo import MongoClient
client = MongoClient()
mov = client.film.movies

# Delete document that matches filter, similar to find_one() res = mov.delete_one({ "title": "gladiator" })
# How many documents were deleted? res.deleted_count
1
Python 中的 MongoDB 入門

同時移除多筆文件

# Delete all really bad movies
res = mov.delete_many({ "rating": { "$lt": 5.0 } })

# How many documents deleted? res.deleted_count
4
  • 刪除是永久動作,無法復原!
  • 在刪除前,務必再次確認條件!
Python 中的 MongoDB 入門

一起來練習吧!

Python 中的 MongoDB 入門

Preparing Video For Download...