L’opérateur $exists
Prenez un moment et exécutez list(mov.find()) : vous verrez que certains films ont un champ box_office et d’autres non. Essayons de mieux comprendre la situation.
Cet exercice fait partie du cours
Introduction à MongoDB en Python
Instructions
- Trouvez tous les documents où le champ
box_officeexiste et stockez l’objet curseur résultant dansbox_curs. - Convertissez l’objet curseur en liste Python et stockez-la dans
box.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Find all documents where box_office is set
box_curs = mov.find({
"____": {
"____": ____
}
})
# Convert from cursor to list
box = ____
print(box)
print(f"{len(box)}/{mov.count_documents({})} movies have the box_office field.")