Skip to content Skip to sidebar Skip to footer

Make Dynamic Query With Mongoose

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 = req.params.index; callback = fu

Solution 1:

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
} };

Post a Comment for "Make Dynamic Query With Mongoose"