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

107
Visualizações
mongoose find method returns an empty array

I have an issue.

I should use the mongoose find() method for some queries. While using the find() method, when I give filter find method works but it doesn't give me value/values.

const messages = await MessageSchema.find({sessionId: sessionId}, {__v: 0, _id: 0, updatedAt: 0}).exec();

The above code is my find method. This code gives me as value, empty array. []

But in this code,

const messages = await MessageSchema.find({}, {__v: 0, _id: 0, updatedAt: 0}).exec();

give me an array and all of the messages are in the array.

But I should use filtering.

This is my message Schema.

const mongoose = require('mongoose');

var schema = new mongoose.Schema({
    participant_name: {type: String},
    message: {type: String},
    sessionId: {type: String},
    participantId: {type: Object}
}, {
    timestamps: true
});


module.exports = mongoose.model("Message", schema)

Could you help me please?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You have to cast your sessionId to Object id type in filtering.

how?

import { Types } from 'mongoose';

const messages = await MessageSchema.find({sessionId: Types.ObjectId(sessionId)}, {__v: 0, _id: 0, updatedAt: 0}).exec();
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