• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

256
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?

almost 3 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.

almost 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda