Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 )

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading