I have document structured like so:
{
key: "apples002",
main: [
{q: "Is the apple green?", a1: "The apple is not green.", a2: "No."},
{q: "What color is the apple?", a1: "The apple is yellow.", a2: "Yellow."}
],
alt: [
{q: "What color is the apple?", a1: "The apple is red."},
{q: "Is the apple yellow?", a1: “The apple is yellow.”, a2: “Yes.”}
]
}
I have seen several examples for updating sub-document fields, but most all of them are cases where the sub-documents have unique ids. I have also learned how to refer to one of the sub-documents by index, e.g. to update the q field on main above (first element):
myDB.update({key: 'apples002'}, {$set: {'main.0.q': 'Updated question goes here'}})
So in my case, I would like to use a variable in place of the array index 0 above. I have tried creating a local var with the correct string value and using it in place of 'main.0.q' above, but that doesn't work. Any ideas?