Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!