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

71
Visualizações
Mongoose ignoring field while trying to save

I am trying to insert a new entry in my collection, the problem is that it ignores both doctorId and patientId while I'am sure they are not undefined. I tried to change the fields types in the definition to strings just to test whether they would be inserted and it still no use.

schema:

const RdvSchema = new mongoose.Schema({
    patientId: {
        type: mongoose.Schema.Types.ObjectId,
        ref: "patients"
    },
    doctorId: {
        type: mongoose.Schema.Types.ObjectId,
        ref: "doctors"
    },
    createdAt: {
        type: Date,
        default: () => Date.now()
    },
    updatedAt: {
        type: Date,
        default: () => Date.now()
    },
    urgent: {
        type: Number,
        default: () => false
    },
    date: Date,
    period: String,
    description: String
})

the function saving the document:

const createRdv = async (req, res) => {
    try {
        console.log("patient id: ", req.body.patientId)
        let rdv = new Rdv({
            "patientId": req.body.patientId,
            "doctorId": req.body.doctorId,
            "description": req.body.description,
            "urgent": req.body.urgent,
            "date": req.body.date,
            "period": req.body.period
        })
        await rdv.save(async (err, rdv) => {
            if (err) {
                console.log(err)
                return res.status(500).send(false)
            }
            try {
                await DoctorRepository.addRdv(req.body.doctorId, rdv._id)
                await PatientRepository.addRdv(req.body.patientId, rdv._id)
            } catch (message) {
                console.log(message)
                res.status(500).send(false)
            }
        })
        res.status(200).send(true)
    } catch (ex) {
        res.status(500).send(false)
    }
}

The inserted document:

{
  "_id": {
    "$oid": "6269603d5f0e45e53a470f50"
  },
  "urgent": 3,
  "date": {
    "$date": {
      "$numberLong": "1653433200000"
    }
  },
  "period": "matin",
  "description": "this is a description",
  "createdAt": {
    "$date": {
      "$numberLong": "1651073085661"
    }
  },
  "updatedAt": {
    "$date": {
      "$numberLong": "1651073085661"
    }
  },
  "__v": 0
}

update: for some reason An old document keeps getting inserted the document has nothing to do with what I was trying to insert. The document is one I had inserted previously through a test using Mocha

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