การลบเอกสาร

MongoDB เบื้องต้นใน Python

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
MongoDB เบื้องต้นใน Python

การลบเอกสารหลายรายการพร้อมกัน

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

# How many documents deleted? res.deleted_count
4
  • การลบเอกสารเป็นการ ถาวร และไม่สามารถยกเลิกได้!
  • ตรวจสอบตัวกรองให้ดีก่อนลบ!
MongoDB เบื้องต้นใน Python

มาฝึกกันเถอะ!

MongoDB เบื้องต้นใน Python

Preparing Video For Download...