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

88
Visualizações
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 Respostas
Responde à pergunta

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