Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

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

7 months 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.

7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos