Exercise

List fields of a document

The .find_one() method of a collection can be used to retrieve a single document. This method accepts an optional filter argument that specifies the pattern that the document must match. You will learn more about filters in the next lesson, but for now, you can specify no filter or an empty document filter ({}), in which case MongoDB will return the document that is first in the internal order of the collection.

This method is useful when you want to learn the structure of documents in the collection.

In Python, the returned document takes the form of a dictionary:

    sample_doc = {'id' : 12345, 'name':'Donny Winston', 'instructor': True}

The keys of the dictionary are the (root-level) "fields" of the document, e.g. 'id', 'name','instructor'.

Instructions 1/3

undefined XP
    1
    2
    3
  • Connect to the nobel database.