MongoDB Attendance System for Students of a Faculty [closed]

So I will be giving your my approach and could be a naive way of approaching this because I am not yet that good with refs in MongoDB but this definitely could be one of the many solutions

So from what I understand we would need the following:

  • Student Model
  • Class Model

Now lets build student Model:

const studentSchema = mongoose.Schema({

    firstName:{type:String , required:true},
    lastName:{type:String, required:true},
    studentNumber:{type:String, required:true, unique:true},//We definitely need uniquely identify students and with student number we can achieve that 
    classesEnrolled:{type:Array, required:true}
})

const studentModel = mongoose.model('studentModel', studentSchame);

Now lets build class model:

const classSchema = mongoose.Schema({

    educator:{type:String, required:true},//Every class has and educator
    module:{type:String, required:true, unique:true},//Every class has a module e.g Mat105 etc depending on how the institution name their modules
    studentsEnrolled:{type:Array, default:[]},//Giving this a default and not requiring it cause a module can be instantiated and not having students as yet 
    attendance:{
        
        date:{type:Date, required:true},
        studentsAttended:{type:Array, default:[]},//Catering for the fact that a class when created wont have any attendance has a default of empty array but as classes occur then update in document will be key

    }

})

So now we have both models that we want to work with I will give below scenarios on how I will then handle this process of enrolling students etc:

Case1. New Student enrolling:

  • So here when you have new student enrolling you need all the compulsory identity information.
  • Now in all the information you are to required all the modules that this student is enrolling into
  • Once you have received all the modules now what I would do is now go to the classes model and query all the modules given by the student and the update the studentsEnrolled list by adding the new student.
  • After updating each and every module array I then update the document within database

Case2: New Module creation

  • This should be the easiest and quickest.
  • I would require all the information about the module that are compulsory like educator, module name etc knowing that the rest will have a default value
  • However you are not to bluntly add a new module you are to validate if it does not exist then if it does then return a 404 to client

Case3: Getting number of student enrolled in module

  • This should also be easy
  • Firstly you are to query for the module that you want to get info on
  • Then once you have that lets say you stored the doc in variable module
  • Then you realize I am sure that now you have access to module.studentEnrolled which is an array
  • Now you can just then return back to to the client module.studentEnrolled.length this will give you the number of student enrolled.

Case4: Attendance

  • Now this lets assume that your web/mobile app you have a dashboard where a list of students are there
  • On beside the name of each and every student you have a button made saying Attended and Absent
  • So solution that I am thinking while writing is, in your client when you click either Attended or Absent you forward also send the current date using the JavaScript date module
  • So now in your back-end you will receive student number and current date also module name
  • How then you proceed is you query for the module that you want update the attendance register. lets say it’s saved in variable module
  • Now what you want to do is filter the module.attendance by the date that you received save that array in todaysAttendance
  • Validate if todayAttendance actually is giving back and array if not then you want to start a new register of the current day then save in db and operation is done
  • Else if you got back an array then what you do is add the student number which you received at the back-end to the array
  • Then finally what you want to do is you want map through the todaysAttendance list find the current day array and replace it with your new updated array then take the variable module now that is updated and then update the modudle in mongoDB with the new module in memory that is updated then you done

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top