So I'm randomly generating a work schedule that I generate into a csv. Recently i implemented MongoDB into it so I can reliably store the objects I generate. The thing is, when I use the "old method" of:
It works as intended.
But when I try:
I get a completely different result.
The strangest thing is: When I stringify and save them into a JSON file they are COMPLETELY IDENTICAL. Same with logging them.
I can't really show the output cause of some sensitive information, I can maybe redact it enough if needed. The main thing is: the cells that would recieve values from the "intervals" array's objects are reciving the whole "intervals" array or sometimes the whole schedule object. What am I missing?
my index.js:
import employeeScheduleCsvGenerator from "./tools/employeeScheduleCsvGenerator.js";
import generateWorkSchedule from "./tools/generateWorkSchedule.js";
import parseWorkbookToObject from "./tools/parseWorkbookToObject.js";
import mongoose from "mongoose";
import fs from 'fs'
var month = 9
var year = 2021
await mongoose.connect('mongodb://localhost:27017/test')
.then(console.log("Connected to database"))
.catch(err => console.log(err))
//mongoose.set('debug', true)
const scheduleSchema = new mongoose.Schema({
name_of_schedule: String,
schedule:[{
name_of_workday: String,
day_code: String,
start_of_daily_work: String,
costplace: String,
date: String,
intervals: [{
end_of_interval: String,
type_of_time: String,
worknumber: String,
operation: String,
_id: false
}],
_id: false
}
]
})
const Schedule = new mongoose.model('Schedule', scheduleSchema)
var generatedSchedule = generateWorkSchedule(9,2021)
const firstSchedule = new Schedule({name_of_schedule: "Teszt",schedule: generatedSchedule})
firstSchedule.save(function (err) {
if (err) return err
})
fs.writeFileSync("./json_templates/schedule_with_mongo.json", JSON.stringify(firstSchedule.schedule))
fs.writeFileSync("./json_templates/schedule_without_mongo.json", JSON.stringify(generatedSchedule))
var employees = await parseWorkbookToObject("./xlsx/dolgozoi_nevsor.xlsx", 1);
employeeScheduleCsvGenerator(employees, firstSchedule.schedule, false, year + "" + month + " Beosztas");
employeeScheduleCsvGenerator(employees, firstSchedule.schedule, true, year + "" + month + " Jelenlet");