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

778
Vistas
How do I get only the documents that dont have 'false' in an array of boolean values?

Suppose I have these documents:

[
    {
        _id: 132143124,
        orders: [true, false, false],
    },
    {
        _id: 3123,
        orders: [true, true, true],
    },
];

How do I get only the documents that dont have 'false' in their orders array. I need an aggregate stage solution. ( MongoDB aggregate solution )

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use $not or $ne ( as Mongo's query language flattens arrays ) for this, like so:

db.collection.find({
  orders: {$ne: false}
})

Mongo Playground

same syntax will work in the aggregation pipeline: Mongo Playground Aggregation

about 4 years ago · Juan Pablo Isaza Denunciar

0

You could use filter function for arrays:

const results = [
  {
    _id: 1,
    orders: [true, false, false],
  }, {
    _id: 2,
    orders: [true, true, true],
  }
]
    
const filtered_results = results.map(({orders, ...data}) => {
  return {
    orders: orders.filter((order)=>order === true), 
    ...data
  }
})
    
console.log(filtered_results)

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