BaşlayınÜcretsiz Başlayın

Inserting a single document

After plenty of practice reading and filtering data, the time has come to switch roles and start adding documents to your MongoDB collection.

⚠️ Heads up! The exercises in this chapter modify the database. If you run the same code multiple times, you may see different results. Refresh the page if you want to start with a clean slate.

Bu egzersiz

Introduction to MongoDB in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Complete the dictionary new_movie so it has the genres "drama" and "mystery".
  • Insert new_movie into the movies collection of the film database.
  • Print out the auto-generated id of the newly inserted document.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Complete the definition of new_movie
new_movie = {
    "title": "the prestige",
    "genre": ____,
    "release_year": 2006,
    "rating": 8.5,
    "won_oscar": False
}

# Insert new_movie into movies collection 
res = ____

# Print its auto-generated id
print(res.____)
Kodu Düzenle ve Çalıştır