Displaying Data from MangoDB Connection

HELLO, I’m currently developing a web application for a recommendation system that operates locally and retrieves data from MongoDB. The application workflow begins with a student logging in using their unique student ID and password. Upon successful verification of these credentials, the system should grant access to the student, displaying personalized recommendations fetched from the MongoDB database associated with their student ID. However, despite successful login attempts, the system consistently returns a message indicating that no student ID is available, preventing the display of recommendations.


def recommendations_page(student_id):
# Ensure student_id is a string
student_id = str(student_id)
print(“Searching recommendations for student ID:”, student_id)

# Query the job recommendations collection for the specified student_id
recommendations_cursor = job_recommendations_collection.find({"Student_ID": student_id})
recommendations_count = 0

# Count the number of recommendations for the student
for _ in recommendations_cursor:
    recommendations_count += 1

if recommendations_count > 0:
    print("Recommendations found for student ID:", student_id)
    # Reset cursor to the beginning
    # Iterate over the cursor to find the matching document
    for document in recommendations_cursor:
        if document["Student_ID"] == student_id:
            recommended_job_title = document.get("Recommended_Job_Title", "No recommendation found")
            company = document.get("Company", "")
            location = document.get("Location", "")
            job_link = document.get("Job_Link", "")
            similarity_score = document.get("Similarity_Score", "")
            st.write(f"Recommended Job Title: {recommended_job_title}")
            st.write(f"Company: {company}")
            st.write(f"Location: {location}")
            st.write(f"Job Link: {job_link}")
            st.write(f"Similarity Score: {similarity_score}")
    print("No recommendation found for student ID:", student_id)
    st.error("No recommendations found for this Student ID.")