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

87
Views
how to apply filter on field using multiple values in mongoose

i have a model that contain field state type of enum and accept only three values

active
disabled
deleted

and currently am filtering to get all the active ones by

const query = {state : "active" ... other filters here}
const posts = await post.find(query)

but I have a case where I need to get the posts that have stated both active and disabled and I searched in mongoose docs for something I can use but I find nothing at the moment i want something clean that achieve this code

const query1 = {state : "active" ... other filters here}
const posts1 = await post.find(query1)

const query2 = {state : "disabled" ... other filters here}
const posts2 = await post.find(query2)

const posts = {...posts1, ...posts2}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

const query = { state: { $in: [ "active", "disabled"] } }
const posts = await post.find(query)

This will result in a list of posts whose state is either active or disabled.

The $in operator selects the documents where the value of a field equals any value in the specified array. To specify an $in expression, use the following prototype:

From MongoDB docs.

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!