My document has an array
of arrays
and I would like to filter based on matching 1 value from the lowest arrays.
The basic structure of my document is (there are other fields but they aren’t required to demonstrate):
{
"_id": {
"$oid": "60701a691c071256e4f0d0d6"
},
"schema": {
"$numberDecimal": "1.0"
},
"playerName": "Dan Burt",
"comp": {
"id": {
"$oid": "607019361c071256e4f0d0d5"
},
"name": "Roll Up 2021",
"tees": "Blue",
"roundNo": {
"$numberInt": "1"
},
"scoringMethod": "Stableford"
},
"holes": [
{
"holeNo": {
"$numberInt": "1"
},
"holePar": {
"$numberInt": "4"
},
"holeSI": {
"$numberInt": "3"
},
"holeGross": {
"$numberInt": "4"
},
"holeStrokes": {
"$numberInt": "1"
},
"holeNett": {
"$numberInt": "3"
},
"holeGrossPoints": {
"$numberInt": "2"
},
"holeNettPoints": {
"$numberInt": "3"
}
}
]
}
In the Atlas UI, it looks like this:
The holes
array is made up of another array per hole played.
I would like to filter only the round
's where holes.X.holeGross
equals 2 (i.e. made a birdie on a par 3 for those familiar with golf) for a specific comp._id
and comp.roundNo
.
But I don’t want to loop through and process this. I think an aggregation
query or pipeline can be used, but I cannot fathom how to use them, or even how to begin typing stuff into the Atlas UI to start test queries…
I am reading the documentation, found some StackOverflow articles and watched a few Youtube videos, but I am struggling to replicate for my particular situation of this additional sub-array.