Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
Getting different results when using mongodb object vs code object

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:

  • generating it
  • storing it in a value
  • passing it to the generator function

It works as intended.

But when I try:

  • creating it in mongo (schema, model, new document)
  • and passing the "schedule" array into the function

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");

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!