Inizia subitoInizia gratis

Retrieving a specific document using .find_one()

Where .find() returns a cursor to all documents matching a filter query, .find_one() returns the first document that matches the filter query. This is useful for specific use cases (like looking for a specific movie), as well as for limiting how many results the MongoDB server returns.

To refresh your memory on all available fields in the movies collection, the first document in the collection has been printed for you.

Questo esercizio fa parte del corso

Introduction to MongoDB in Python

Visualizza corso

Istruzioni dell'esercizio

  • Find the movie with the title "her" (casing matters!) and store the resulting document as the variable her.
  • Find a movie that has "adventure" among its genres and store it as a variable adv.

esercizio interattivo pratico

Prova questo esercizio completando questo codice di esempio.

# Find the movie with the title "her"
her = mov.find_one(____)
print(her)

# Find a movie with "genre" of "adventure"
adv = mov.____
print(adv)
Modifica ed esegui il codice