Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/00_open_mongodb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"source": [
"# Open MongoDB Using the MongoDB Extension\n",
"\n",
"1. click on the MongoDB extension on the side panel\n",
"1. Click on the MongoDB extension on the side panel\n",
"2. To connect to the local database, click on ‘Library DB’ in the list of connections on the left side"
]
},
Expand Down
2 changes: 1 addition & 1 deletion python/01_connect_database.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"source": [
"## Select the Python Kernel\n",
"\n",
"To run the code cells in these notebooks you need to select the appropriate kernel (programming language). In this case is Python. Click on the `Select Kernel` button at the top right, then `Python Environments` > `Choose the recommended Python environment`"
"To run the code cells in these notebooks you need to select the appropriate kernel (programming language). In this case is Python. Click on the `Select Kernel` button at the top right, then `Python Environments` > `Choose the recommended Python environment`. For this workshop, we will use Python 3.11."
]
},
{
Expand Down
41 changes: 3 additions & 38 deletions python/10_find.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise: find all the books that have less than 50 pages and print only the title and pages"
"## Find all the books that have less than 50 pages and print only the title and pages"
]
},
{
Expand All @@ -93,11 +93,7 @@
"metadata": {},
"outputs": [],
"source": [
"filter = { \n",
" \"$and\": [\n",
" { \"pages\": { \"$lt\": 50 }}\n",
" ]\n",
"}\n",
"filter = { \"pages\": { \"$lt\": 50 } }\n",
"\n",
"projection = { \"title\": 1, \"pages\": 1 }\n",
"\n",
Expand All @@ -107,33 +103,6 @@
" print(book) "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Find all the books that have less than 50 pages and project only the title and pages"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"filter = { \n",
" \"$and\": [\n",
" { \"pages\": { \"$lt\": 50 }}\n",
" ]\n",
"}\n",
"\n",
"projection = { \"title\": 1, \"pages\": 1 }\n",
"\n",
"cursor = books.find(filter, projection).limit(10)\n",
"\n",
"for book in cursor:\n",
" print(book)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -147,11 +116,7 @@
"metadata": {},
"outputs": [],
"source": [
"filter = { \n",
" \"$and\": [\n",
" { \"pages\": { \"$lt\": 50 }},\n",
" ]\n",
"}\n",
"filter = { \"pages\": { \"$lt\": 50 } }\n",
"\n",
"projection = {\n",
" \"_id\": 0,\n",
Expand Down
2 changes: 1 addition & 1 deletion python/11_find_arrays.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
" {\"genres\": {\"$in\": \n",
" [\"Family Life\", \"Fiction\"]\n",
" }\n",
" }).limit(10)\n",
" }).limit(15)\n",
"\n",
"for book in cursor:\n",
" print(f'{book[\"title\"]} - genre: {book[\"genres\"]}')\n",
Expand Down
37 changes: 4 additions & 33 deletions python/20_project_sort_limit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"id": "4",
"metadata": {},
"source": [
"## Sort books by descending number of pages"
"## Use limit() and sort() books by descending number of pages"
]
},
{
Expand All @@ -73,35 +73,6 @@
" print(book)"
]
},
{
"cell_type": "markdown",
"id": "6",
"metadata": {},
"source": [
"## Limit"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7",
"metadata": {},
"outputs": [],
"source": [
"projection = {\n",
" \"title\": 1,\n",
" \"pages\": 1\n",
"}\n",
"\n",
"cursor = books.find(\n",
" {}, # empty filter, all books\n",
" projection\n",
").sort(\"pages\", -1).limit(10)\n",
"\n",
"for book in cursor:\n",
" print(f\"{book['title']} - {book['pages']}\")"
]
},
{
"cell_type": "markdown",
"id": "8",
Expand All @@ -119,13 +90,13 @@
"source": [
"projection = {\n",
" \"title\": 1,\n",
" \"pages\": 1\n",
" \"year\": 1\n",
"}\n",
"\n",
"cursor = books.find({}, projection).sort(\"pages\", -1).skip(4).limit(10)\n",
"cursor = books.find({}, projection).sort(\"year\", -1).skip(4).limit(10)\n",
"\n",
"for book in cursor:\n",
" print(f\"{book['title']}\")"
" print(f\"{book['title']} - {book['year']}\")"
]
},
{
Expand Down