Get startedGet started for free

Count documents in a collection

In the video, you learned that a MongoDB database can consist of several collections. Collections, in turn, consist of documents, which store the data.

You will be working with the Nobel laureates database which we have retrieved as nobel. The database has two collections, prizes and laureates. In the prizes collection, every document correspond to a single Nobel prize, and in the laureates collection - to a single Nobel laureate.

Recall that you can access databases by name as attributes of the client, like client.my_database (a connected client is already provided to you as client). Similarly, collections can be accessed by name as attributes of databases (my_database.my_collection).

Use the console on the right to compare the number of laureates and prizes using the .count_documents() method on a collection (don't forget to specify an empty filter document as the argument!), and pick a statement that is TRUE.

This exercise is part of the course

Introduction to MongoDB in Python

View Course

Hands-on interactive exercise

Turn theory into action with one of our interactive exercises

Start Exercise