'How to substitute $ for a parameter in Array Update Operators [Mongoose]

I have an apparently simple question, is it possible for me to replace the $ operator used to identify the index of an attribute array inside the mongoose for a variable that I have already passed as a parameter?

i.e. transform

$set: {"img.$]": req.params.imgUrl}

into something like

const indexDesired = req.params.indexParams // 0, 1 , 2

$set: {"img.indexDesired]": req.params.imgUrl}

thanks in advance for any and all help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source