Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda