I am seeking a way to count the number of items in an array of JSON objects that meet specific conditions. The structure of my array is as follows:
array = [{
name: 'Bob',
age: 24
},
....,
{
name: 'Mary',
age: 23
}]
Instead of iterating through the entire array, I would like to find an expression similar to a database query for simplicity and elegance:
db.myCollection.find({ age: 23 }).count()
Are there any recommended best practices for this task? I have considered using the underscore library but haven't found exactly what I need.
Your assistance is greatly appreciated.