We are moving away from MongoDB shell to Python, where we are interacting with the MongoDB database with scripts.

Do you still remember how we were scraping web sites? MongoDB is an excellent choice for storing such data because web pages are unstructured data that can be parsed into a NoSQL database.

Introduction to PyMongo

Let’s open up the file(s) in the 01-Ins_PyMongo folder to get started.

Installing PyMongo
  • Activate your dev environment on conda: conda activate dev
  • To install PyMongo into your dev environment, type: conda install -c anaconda pymongo
  • To check if your PyMongo is installed, type: conda list pymongo

Ref: https://pymongo.readthedocs.io/en/stable/api/pymongo/collection.html?highlight=find#pymongo.collection.Collection.find

Students Do: Mongo Class

PyMongo with Imported CSV Data

Let’s open up the file(s) in the 03-Ins_PyMongo_with_Imported_Data folder to get started.

To import the CSV customer dn from your directory into a Mongo database, type:

mongoimport --type csv -d petsitly_marketing -c customer_list --headerline --drop customer_database.csv

Students Do: PyMongo with Imported JSON Data

Importing Data, Accessing Nested Data, and Modifying Data Types

Let’s open up the file in the 05-Ins_SelectingFields folder to get started.

		mongoimport --type json -d autosaurus -c mechanics --drop --jsonArray mechanics.json
		mongoimport --type csv -d autosaurus -c customers --headerline --drop customers.csv

Students Do: Air Fields

Comparison Operators

Let’s open up the file(s) in the 07-Ins_ComparisonFilters folder to get started.

Students Do: Find Pets

Sort and Limit

Let’s open up the file(s) in the 09-Ins_SortAndLimit folder to get started.

Students Do: Sort and Limit Pets