Ty very much for you reply.
const classSchema = new mongoose.Schema({
ClassName: String,
Section: Array,
fee: Number,
});
const employeeModel = new mongoose.Schema({
first_name: {
type: String,
required: true,
},
last_name: {
type: String,
required: true,
},
gender: {
type: String,
enum: ["Male", "Female"],
required: true,
},
type: {
type: String,
enum: ["Teaching", "Non Teaching"],
required: true,
},
father_name: {
type: String,
// required: true,
},
address: {
type: String,
// required: true,
},
cnic: {
type: Number,
},
phone: {
type: Number,
required: true,
},
dob: {
type: Date,
// required: true,
// set: (val) => {
// const [day, month, year] = val.split("/");
// return new Date(year, month - 1, day);
// },
},
last_qualification: {
type: String,
},
passing_year: {
type: Number,
},
marks_obtained: {
type: String,
},
board_uni: {
type: String,
},
designation: {
type: String,
required: true,
},
joining_date: {
type: Date,
// set: (val) => {
// const [day, month, year] = val.split("/");
// return new Date(year, month - 1, day);
// },
},
package: {
type: Number,
required: true,
},
status: {
isActive: {
type: Boolean,
default: true,
},
comments: {
type: Array,
default: [],
},
},
});
const PaymentSchema = new mongoose.Schema(
{
studentId: { type: String, required: true },
ClassName: { type: String, required: true },
Section: {
type: String,
enum: ["A", "B", "C", "D", "E"],
required: true,
},
amount: Number,
date: Date,
payId: String,
},
{ timestamps: true }
);
const studentMODEL = new mongoose.Schema({
Name: {
type: String,
required: true,
},
DOB: {
type: Date,
required: true,
},
Gender: {
type: String,
required: true,
},
Father_Name: {
type: String,
required: true,
},
Phone_No: {
type: String,
required: true,
},
Address: {
type: String,
required: true,
},
ClassID: {
type: String,
required: true,
},
Section: {
type: String,
required: true,
},
createdAt: {
type: Date,
},
status: {
isActive: {
type: Boolean,
default: true,
},
comments: {
type: Array,
default: [],
},
},
});
I issue is that I have to run a lot of complex queries and my collections are very intertwined. For some reason my query time has shot up to unrealistic times especially for the students collection where I am housing 1400 documents. And if you look closely at payments I am making invoking functions to dynamically generate payID which I think is a great solution to restrict to the user for making duplicate entries for fee payment of a monthly fee payment twice. Again the price I am paying over here is with performance. Can you please guide me on what approach to take. I am thinking of implementing a service oriented architecture to have cacheing coupled with mongo to improve performance but the implementation Im am not very comfortable with. Also it has made me to rethink the api paradigm because using only the restful approach is making the code unmaintainable and libraries like graphql keep making breaking changes so its not a comfortable fall back.