I have a hard time understanding how to do queries on arrays. A basic example, If I take this document:
Man
children
Frank
age: 33
Anna
age: 28
How do I find all the children who have an age greater than 30?
Thanks!
I have a hard time understanding how to do queries on arrays. A basic example, If I take this document:
Man
children
Frank
age: 33
Anna
age: 28
How do I find all the children who have an age greater than 30?
Thanks!
The query of @Veeram works pretty well:
db.getCollection('men').aggregate([
{ $match: {'children.age': {$gt:30}} },
{ $project: { children: {$filter: { input: '$children', as: 'child', cond: {$gt: ['$$child.age', 30]} }}, _id: 0 }}
])
This link helped me to understand.