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

331
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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