from pymongo import MongoClient

# MongoDB connection string 
url = "mongodb+srv://admin:<EMAIL>@<EMAIL>.mongodb.<EMAIL>/myFirstDatabase?retryWrites=true&w=majority"

# connect to the MongoDB cluster 
client = MongoClient(url)

# connect pytech database
db = client.pytech

# get the students collection 
students = db.students

# find all students in the collection 
student_list = students.find({})

# display message 
print("\n  -- DISPLAYING STUDENTS DOCUMENTS FROM find() QUERY --")

# loop over the collection and output the results 
for doc in student_list:
    print("  Student ID: " + doc["student_id"] + "\n  First Name: " + doc["first_name"] + "\n  Last Name: " + doc["last_name"] + "\n")

# find document by student_id
jennie = students.find_one({"student_id": "1008"})

# output the results 
print("\n  -- DISPLAYING STUDENT DOCUMENT FROM find_one() QUERY --")
print("  Student ID: " + jennie["student_id"] + "\n  First Name: " + jennie["first_name"] + "\n  Last Name: " + jennie["last_name"] + "\n")

# exit message 
input("\n\n  End of program, press any key to continue...")

from pymongo import MongoClient

# MongoDB connection string 
url = "mongodb+srv://admin:<EMAIL>@<EMAIL>.mongodb.<EMAIL>/myFirstDatabase?retryWrites=true&w=majority"

# connect to the MongoDB cluster 
client = MongoClient(url)

# connect pytech database
db = client.pytech

# get the students collection 
students = db.students

# find all students in the collection 
student_list = students.find({})

# display message 
print("\n  -- DISPLAYING STUDENTS DOCUMENTS FROM find() QUERY --")

# loop over the collection and output the results 
for doc in student_list:
    print("  Student ID: " + doc["student_id"] + "\n  First Name: " + doc["first_name"] + "\n  Last Name: " + doc["last_name"] + "\n")

# find document by student_id
jennie = students.find_one({"student_id": "1008"})

# output the results 
print("\n  -- DISPLAYING STUDENT DOCUMENT FROM find_one() QUERY --")
print("  Student ID: " + jennie["student_id"] + "\n  First Name: " + jennie["first_name"] + "\n  Last Name: " + jennie["last_name"] + "\n")

# exit message 
input("\n\n  End of program, press any key to continue...")

# MongoDB connection string # connect to the MongoDB cluster # connect pytech database # get the students collection # find all students in the collection # display message # loop over the collection and output the results # find document by student_id # output the results # exit message