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

776
Views
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 answers
Answer question

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 Report

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