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

332
Vistas
Mongoose array in document does not exist when queried

I need to query for all documents with an array but the returned documents dont have the array.

query

(async () => {
        const data = await Lesson.find({signed: {$exists: true}});
        console.log(data[0].signed); # undefined
})();

model

const lessonSchema = new mon.Schema(
    {
        day: Number,
        startTime: Number,
        endTime: Number,
        description: {type: String, trim: true},
        signed: [mon.Schema.Types.ObjectId]
    }, 
    {
        collection: 'lessons'
    }
);
module.exports = mon.model("Lesson", lessonSchema);

I checked the database and the documents do have the array. The query retrieve everything except for the array (all of the documents and their values except for the array). NOTE: in the database I have only two test documents. both have an array and both don't have the array in the query.

Thanks

EDIT: I found out that if I remove the signed property from the schema it works. Why?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I had this problem because the type of signed was objectId and the ids I used were strings. I cleared the array and added real ObjectId and it worked.

about 4 years ago · Juan Pablo Isaza Denunciar
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