L'opérateur $exists
Prenez un moment et exécutez list(mov.find()) : vous verrez que certains films ont un champ box_office alors que d'autres non. Voyons la situation de plus près.
Cette activité fait partie du cours
Introduction à MongoDB en Python
Instructions de l’exercice
- Trouvez tous les documents où le champ
box_officeexiste et enregistrez l'objet curseur obtenu dansbox_curs. - Convertissez l'objet curseur en liste Python et enregistrez-la dans
box.
Exercice interactif pratique
Essayez cet exercice en complétant ce code d’exemple.
# 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.")