Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

90
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda