This project contains tasks for MongoDB, a NoSQL database.
-
0. List all databases
0-list_databases contains a MongoDB script that lists all databases in MongoDB. -
1. Create a database
1-use_or_create_database contains a MongoDB script that creates or uses the databasemy_db
. -
2. Insert document
2-insert contains a MongoDB script that inserts a document in the collectionschool
:- The document must have one attribute
name
with value “Holberton school”. - The database name will be passed as an option of
mongo
command.
- The document must have one attribute
-
3. All documents
3-all contains a MongoDB script that lists all documents in the collectionschool
:- The database name will be passed as an option of
mongo
command.
- The database name will be passed as an option of
-
4. All matches
4-match contains a MongoDB script that lists all documents withname="Holberton school"
in the collectionschool
:- The database name will be passed as an option of
mongo
command.
- The database name will be passed as an option of
-
5. Count
5-count contains a MongoDB script that displays the number of documents in the collectionschool
:- The database name will be passed as an option of
mongo
command.
- The database name will be passed as an option of
-
6. Update
6-update contains a MongoDB script that adds a new attribute to a document in the collectionschool
:- The script should update only document with
name="Holberton school"
(all of them). - The update should add the attribute
address
with the value “972 Mission street”. - The database name will be passed as an option of
mongo
command.
- The script should update only document with
-
7. Delete by match
7-delete contains a MongoDB script that deletes all documents withname="Holberton school"
in the collectionschool
:- The database name will be passed as an option of
mongo
command.
- The database name will be passed as an option of
-
8. List all documents in Python
8-all.py contains a Python function that lists all documents in a collection:- Prototype:
def list_all(mongo_collection):
. - Return an empty list if no document in the collection.
- mongo_collection will be the pymongo collection object.
- Prototype:
-
9. Insert a document in Python
9-insert_school.py contains a Python function that inserts a new document in a collection based onkwargs
:- Prototype:
def insert_school(mongo_collection, **kwargs):
. mongo_collection
will be thepymongo
collection object.- Returns the new
_id
.
- Prototype:
-
10. Change school topics
10-update_topics.py contains a Python function that changes all topics of a school document based on the name:- Prototype:
def update_topics(mongo_collection, name, topics):
. mongo_collection
will be thepymongo
collection object.name
(string) will be the school name to update.topics
(list of strings) will be the list of topics approached in the school.
- Prototype:
-
11. Where can I learn Python?
11-schools_by_topic.py contains a Python function that returns the list of school having a specific topic:- Prototype:
def schools_by_topic(mongo_collection, topic):
. mongo_collection
will be thepymongo
collection object.topic
(string) will be topic searched.
- Prototype:
-
12. Log stats
12-log_stats.py contains a Python script that provides some stats about Nginx logs stored in MongoDB:- Database:
logs
. - Collection:
nginx
. - Display:
- First line:
x logs
wherex
is the number of documents in this collection. - Second line:
Methods:
. - 5 lines with the number of documents with the
method
=["GET", "POST", "PUT", "PATCH", "DELETE"]
in this order (see example below - warning: it’s a tabulation at the start of each line). - One line with the number of documents with:
method=GET
.path=/status
.
- Example:
94778 logs Methods: method GET: 93842 method POST: 229 method PUT: 0 method PATCH: 0 method DELETE: 0 47415 status check
- First line:
- You can use this dump as data sample: dump.zip.
- Database:
-
13. Regex filter
100-find contains a MongoDB script that lists all documents withname
starting byHolberton
in the collectionschool
:- The database name will be passed as an option of the
mongo
command.
- The database name will be passed as an option of the
-
14. Top students
101-students.py contains a Python function that returns all students sorted by average score:- Prototype:
def top_students(mongo_collection):
.mongo_collection
will be thepymongo
collection object.
- The top must be in descending order of average score.
- The average score must be part of each item returns with key =
averageScore
. - A sample document in the collection is shown below:
{ "name": "Julia", "topics": [ { "title": "Algo", "score": 10.5 }, { "title": "C", "score": 10.2 }, { "title": "Python", "score": 10.1 } ] }
- Prototype:
-
15. Log stats - new version
102-log_stats.py improves 12-log_stats.py by adding the top 10 of the most present IPs in the collectionnginx
of the databaselogs
:- The top 10 IPs must be sorted.
- Festus Maithya festusmaithyakcau
All work contained in this project was completed as part of the curriculum for ALX School. ALX School is a campus-based full-stack software engineering program that prepares students for careers in the tech industry using project-based peer learning. For more information, visit this link.