I am trying to make a dynamic condition using Mongoose but it doesn\'t work as I imagined.
the code is like this
id = req.params.questionId;
index =
You need to create your updates
object in two steps:
var updates = { $push: {} };
updates.$push["array.$.array2." + index + ".answeredBy"] = userId;
Update
Now that node.js 4+ supports computed property names, you can do this in one step:
var updates = { $push: {
["array.$.array2." + index + ".answeredBy"]: userId
} };