I am trying to query a nested array based on indexes from my mongodb database but I am having a difficult time building my query. My question is if it is possibly to build a mongodb query for nested arrays like you can natively in JavaScript
workouts[0][0].exercises[0]
I need to be able to pass in a variable for each [0] above so that I can update or find each specific exercise in each specific week. I know from reading the docs and other questions related to nested arrays is that mongodb has a difficult time doing this if I read correctly. If that is the case is there a better way to structure my data so that it would be easier to query with mongodb or do I just have to grab the entire object and filter through it myself with JavaScript?
{
"_id" : "Qr8bHSm2tHunvWdmY",
"owner" : "xaSeX4yXbiXJZ8XZp",
"name" : "Fourth Program",
"weeks" : "1",
"workouts" : [ // array to hold each week
[ // individual week array
{
"day" : 1,
"exercises" : [
{
"exercise" : "Bench press",
"weight" : "185",
"reps" : "8",
"sets" : "4"
},
{
"exercise" : "Shoulder press",
"weight" : "135",
"reps" : "8",
"sets" : "4"
}
]
},
{
"day" : 2,
"exercises" : [
{
"exercise" : "Sqaut",
"weight" : "225",
"reps" : "10",
"sets" : "3"
},
{
"exercise" : "Deadlift",
"weight" : "300",
"reps" : "5",
"sets" : "3"
}
]
}
]
]
}