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
MongoDB parameters to filter through array

I have a problem through an array with mongoDB parameters... assuming I have this two arrays

const diversityArray = ['video', 'gps']
const entries = [
  {
    name: 'First entry',
    slug: 'first',
    diversity: 'image, video'
  },
  {
    name: 'Second entry',
    slug: 'second',
    diversity: 'image, gps'
  },
  {
    name: 'Third entry',
    slug: 'third',
    diversity: 'iframe'
  }];

How could I do this but with mongoDB parameters? I want to filter all the items in the array that contains one or more of the items on the diversityArray.

const filtered = entries.filter(item => diversityArray.some(data => item.diversity.includes(data)));

I need to do this because I have a larger and more complex array coming from Builder.io Headless CMS and I want to do the filter in the query.

I have this code right now:

    const sets = await builder.getAll('open-dataset', {
      options: { noTargeting: true },
      limit: 100,
      query: {
        data: {
          date: { $gt: newMinYear, $lt: newMaxYear },
          title: { $regex: search, $options: 'i' },
          diversity: ...what I want to do
        }
      }
    });

Thanks!

about 4 years ago · Juan Pablo Isaza
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