Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

70
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda