I have this document (sample document given here. All my documents in the collection follow same model) in MongoDB because I'm using Mongoose to connect to MongoDB from my node application.
{
"_id": {
"$oid": "60dd9e83c462bb92f5b0227d"
},
"Email": "xyz@anonymus.com",
"__v": {
"$numberInt": "0"
},
"work_days": {
"monday": {
"start": "9.30",
"end": "16.20",
"list_of_blocked_apps": ["Facebook", "Instagram", "Whatsapp", "Snapchat", "Tiktok"]
},
"tuesday": {
"start": "9.30",
"end": "16.20",
"list_of_blocked_apps": ["facebook", "instagram", "whatsapp", "tiktok"]
},
"friday": {
"start": "11.10",
"end": "17.00",
"list_of_blocked_apps": ["tiktok"]
}
}
}
And I have to design a function that takes Email and week_Day as input and gives out list of blocked apps, start and end as output basically the value of the week_day key.
Example:
const datamodel = require("./model");
const findSchedule = async(email, week_Day) => {
// Mongoose query here to get the desired output
return day_schedule;
}
Problem
How to design the function to achieve the result. Pardon me if it is a stupid question because I'm just getting started with mongoDB.