Portfolio containing the project from CS-340 Client/Server Development.
The Animal Shelter project creates a package that Python module the provides CRUD (create, read, update, delete) services to the animals collection in the AAC database.
This project exists to make it easier for a user to interact programmatically with the animal collection in the AAC database. This includes making it easy for the user to connect to the database, create new documents in the database, and read from the database.
The purpose of a CRUD Python module is to have reusable code to connect to a database and perform create, read, update, and delete operations on the database.
To get a local copy up and running, follow these steps:
-
Start the MongoDB service
mongod
-
Import the “aac_shelter_outcomes.csv” dataset using the following command
mongoimport --port <PORT#> --db AAC --collection animals --type=csv --headerline <PATH_TO_CSV>aac_shelter_outcomes.csv
-
Launch the Mongo shell and create the admin and aacuser
mongosh db.createUser({user:’admin’,pwd:passwordPrompt(),roles:[{role:’userAdminAnyDatabase’,db:’admin’},’readWriteAnyDatabase’]}) db.createUser({user:’aacuser’,pwd:passwordPrompt(),roles:[{role:’readWrite’,db:’AAC’ }]})
-
Restart MongoDB service with auth
mongod --shutdown mongod
-
From here you can open your Python IDE and install the Animal Shelter package and create a new instance to connect to the database
client = AnimalShelter (<USER>, <PASSWORD>, <PORT>, <AUTH_SRC>)
This module used PyMongo, the Python driver for Mongo, to interact with the database. This is the official Python driver from MongoDB, which means it has a lot of features and is well documented and supported.
-
AnimalShelter(username, password, port = 27017, auth_src_db = 'admin')
The constructor is used to make the initial connection to the database. The username and password parameters are for logging a user into the database. The port parameter has a default value for the default port on a MongoDB instance. A different value can be passed if the default port is not used. The auth_src_database is for specifying which database contains the record for the user login. It has a default value for referencing the admin database. -
create(data)
The create method has a data parameter. This parameter contains the document you want created in the database. The method returns true if the insert is successful and false if it is not. -
read(query)
The read method has a query parameter. The parameter contains the query to be run for a search of the database. If any matches are found, they are returned. -
update(key, data)
The update method has a key and data parameters. The key is the query to match against. Any documents that are found that match the key are then updated with the value from the data parameter. The method returns how many documents matched the key and how many documents were updated. -
delete(key)
The delete method has a key parameter. The key is the query to match against. Any documents that are found that match the key are then deleted. The method returns the number of documents that were deleted.
This resets the filter and displays all animals in the table, updating the widgets accordingly.
This filters to display dogs that meet the requirements for water rescue in the table, updating the widgets accordingly.
This filters to display dogs that meet the requirements for mountain or wilderness rescue in the table, updating the widgets accordingly.
This filters to display dogs that meet the requirements for disaster or individual tracking in the table, updating the widgets accordingly.
MongoDB is a good choice for use with frontend programs. Instead of having to define columns and rows, each record is stored as a document containing all of its own properties and values. This lends itself well to creating interactive dashboards for displaying data.
Python was chosen for this project due to its ease of use and the wide availability of support and add on features and libraries.
PyMongo is the recommend driver for using Python to interact with MongoDb.
Dash is a Python framework that works well for creating web-based dashboards to display data.