{ "cells": [ { "cell_type": "markdown", "id": "58b5ae42-4bad-4a37-a0ee-557f1faa417e", "metadata": {}, "source": [ "# The MongoDB `school` database" ] }, { "cell_type": "code", "execution_count": null, "id": "809a2414-2086-4f37-b9ef-6ae5742f1e43", "metadata": {}, "outputs": [], "source": [ "import pymongo\n", "from pymongo import MongoClient" ] }, { "cell_type": "markdown", "id": "263141a5-76f9-459b-b8b2-da0038a8aa41", "metadata": {}, "source": [ "## The MongoDB server uses port 27017." ] }, { "cell_type": "code", "execution_count": null, "id": "9fd13218-9ffb-4577-9bfb-59a205e13d8c", "metadata": {}, "outputs": [], "source": [ "mongo_uri = 'mongodb://localhost:27017/'\n", "\n", "client = MongoClient(mongo_uri);\n", "client" ] }, { "cell_type": "markdown", "id": "5f4ac65a-719e-4777-b64b-8d0224c2685c", "metadata": {}, "source": [ "## Create the `school` database." ] }, { "cell_type": "code", "execution_count": null, "id": "2f24de40-a21b-427b-bc29-afaf7fb025fc", "metadata": {}, "outputs": [], "source": [ "client.drop_database('school')" ] }, { "cell_type": "code", "execution_count": null, "id": "c24b44d9-3216-4114-a47b-630e84166bb0", "metadata": {}, "outputs": [], "source": [ "school_db = client.school\n", "school_db" ] }, { "cell_type": "code", "execution_count": null, "id": "1c563e54-8828-40d0-94de-af996cdaf910", "metadata": {}, "outputs": [], "source": [ "client.close()" ] }, { "cell_type": "markdown", "id": "f68c24ca-c0a5-4a69-b74b-5c5f91f87f40", "metadata": {}, "source": [ "#### (c) 2023 by Ronald Mak" ] }, { "cell_type": "code", "execution_count": null, "id": "c547e5ee-9805-4346-9891-ef930ae1784b", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.18" } }, "nbformat": 4, "nbformat_minor": 5 }