Skip to content
Snippets Groups Projects
Commit 01890119 authored by William Bell's avatar William Bell
Browse files

Correcting the documentation and code to match current behaviour of find.

parent 89619808
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -184,7 +184,7 @@ The first section of the \texttt{'planets.json'} file is given in Listing~\ref{l
The contents of \texttt{select\_planet.py} are given in Listing~\ref{listing:select_planet.py}. This Python program prints the names of the collections and then checks if the \texttt{'orbit\_data'} collection is present. If the \texttt{'OrbitData'} collection is present, it prints the names of each of the planets and the complete document for Pluto.
The \texttt{find} function at Line 26 includes two arguments, which are each given within \texttt{\{\}} parentheses. The first pair of \texttt{\{\}} parentheses is empty. This is the condition, which is optional. Since the condition is empty, all documents are considered. The second argument is \texttt{\{'name':1, '\_id':0 \}}. The second argument is a list of document fields that should be considered. The format is the field name, a colon and the position number. Setting the position number to zero for the \texttt{\_id} field causes it not to be printed.
The \texttt{find} function at Line 26 includes two arguments, which are each given within \texttt{\{\}} parentheses. The first pair of \texttt{\{\}} parentheses is empty. This is the query condition, which is optional. Since the condition is empty, all documents are considered. The second argument is \texttt{\{'name':1, '\_id':0 \}}. The second argument is a list of document fields that should be enabled or disabled. The format is the field name, a colon and an integer number, where 0 disables the field and 1 enables the field. In general, the \texttt{find} command allows up to three input arguments, as discussed in the \href{https://www.mongodb.com/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find}{MongoDB documenation}.
The \texttt{find\_one} function at Line 32 includes a condition that the field \texttt{'name'} must be equal to \texttt{'Pluto'}. Since the list of fields to be considered is omitted, all fields are returned.
......
......@@ -22,7 +22,7 @@ orbit_data = db["OrbitData"]
# Print the names of the planets.
print(">> The names of the planets:")
for planet in orbit_data.find({}, {'name': 1, 'Number of Moons': 2, '_id': 0}):
for planet in orbit_data.find({}, {'name': 1, 'Number of Moons': 1, '_id': 0}):
print(planet)
print()
......@@ -30,7 +30,7 @@ print()
# Print planets with moons.
print(">> Planets with moons:")
for planet in orbit_data.find({'Number of Moons': {'$gt': 0}},
{'name': 1, 'Number of Moons': 2, '_id': 0}
{'name': 1, 'Number of Moons': 1, '_id': 0}
).sort('Number of Moons'):
print(planet)
print()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment