I'm trying get select data from 1 collection, remove the fields I don't need, and add some new fields, and passing the data needed which is being replicated on each document for the new fields, and save them into a different collection.
Am I getting close or am I way off? Any help would be appreciated.
router.post('', (req, res, next) => {
const taskDay = req.body.taskDay;
switch (taskDay) {
case 'taskSunday':
MasterTask.find({taskSunday: true}).forEach(tempData => {
const taskSheet = new Tasksheet({
taskDate: req.body.taskDate,
taskTicket: req.body.taskTicket,
taskTime: tempData.taskTime,
taskCompany: tempData.taskCompany,
taskDescription: tempData.taskDescription,
taskCompleted: req.body.taskCompleted,
taskComments: req.body.taskComments,
taskCompletedBy: req.body.taskCompletedBy,
taskTimeStamp: req.body.taskTimeStamp,
taskKnowledgeTitle: tempData.taskKnowledgeTitle,
taskKnowledgeUrl: tempData.taskKnowledgeUrl,
taskType: tempData.taskType
});
Tasksheet.insertMany(taskSheet).then(result => {
console.log(result);
res.status(200).json({message: 'task sheet created'})
});
});
break;
Sample Data being pulled in find:
_id: "5f0acb7209e5981d10bb765a",
taskTime: "00:00",
taskCompany: "CompanyName",
taskDescription: "Some Needed Daily Task",
taskSunday: true,
taskMonday: true,
taskTuesday: true,
taskWednesday: true,
taskThursday: true,
taskFriday: true,
taskSaturday: true,
taskDisable: false,
taskEndOfMonth: null,
taskKnowledgeTitle: "Some Title",
taskKnowledgeUrl: "Some URL",
taskForSpecificDays: null,
taskType: "Core",
__v: 0
}
Data transformation that I'm trying to save to new collection:
{
id: "mongooseID",
taskTicket: "",
taskDate: null,
taskTime: "00:00",
taskCompany: "somename",
taskDescription: "This is an example description of a task. This is going to be an extra long line of text to test.",
taskCompleted: false,
taskComments: "",
taskCompletedBy: "",
taskTimeStamp: "",
taskKnowledgeTitle: "Test",
taskKnowledgeUrl: "http://www.google.com",
taskType: "Core"
}