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

241
Views
How to filter in Mongoose?

I want to do a filtering operation on id. I want the data with an id of 3 to be skipped.

Example

const id=3;

const data =[
{id:1},
{id:2},
{id:3},
{id:4},
{id:5},
];

// the result i want

[{id:1},{id:2},{id:4},{id:5}]

How can I do this in Mongoose?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

yourModelName.find({ id: { $ne: 3 } })

$ne: Not equals to

More on find method: https://mongoosejs.com/docs/api/query.html#query_Query-find

ne operator: https://docs.mongodb.com/manual/reference/operator/query/ne/

about 4 years ago · Juan Pablo Isaza Report

0

Find is your friend. You can apply a condition the the fields you want to search by. In this case it's id. $ne is a query condition, meaning Not Equal to the value given.

Your query will look something like this:

const number = 3
const result = await users.find({ id : { $ne: number } })
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!