Ta bort dokument

Introduktion till MongoDB i Python

Filip Schouwenaars

Machine Learning Researcher

Ta bort ett enstaka dokument

# 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
Introduktion till MongoDB i Python

Ta bort flera dokument samtidigt

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

# How many documents deleted? res.deleted_count
4
  • Att ta bort dokument är permanent och kan inte ångras!
  • Kontrollera dina filter noga innan du tar bort!
Introduktion till MongoDB i Python

Nu kör vi en övning!

Introduktion till MongoDB i Python

Preparing Video For Download...