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

106
Vistas
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 Respuestas
Responde la pregunta

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